How to Hide a Divi Module When Scrolling Up or Down

Written by Dan Mossop

In this quick tutorial, I’ll show you how to hide a Divi module when scrolling in a specific direction (up or down), so that the module only shows when you want it to. This is especially useful when using Divi’s Scroll Effects feature and you have a effect you want to play as the user scrolls down, but don't want playing in "reverse" as they scroll back up.

Add the Scroll Detection Code

Paste the following code into your site. You can do this either:

  • In the "Divi > Theme Options > Integration > Add code to the head of your blog" section, or

  • In a Code Module anywhere on your page

<script>
(function() {
  let lastScrollTop = 0;
  let body = document.body;

  window.addEventListener("scroll", function() {
    let currentScroll = window.pageYOffset || document.documentElement.scrollTop;

    if (currentScroll > lastScrollTop) {
      body.classList.add("db-scrolling-down");
      body.classList.remove("db-scrolling-up");
    } else if (currentScroll < lastScrollTop) {
      body.classList.add("db-scrolling-up");
      body.classList.remove("db-scrolling-down");
    }

    lastScrollTop = currentScroll <= 0 ? 0 : currentScroll;
  }, false);
})();
</script>

<style>
body.db-scrolling-up .db-hide-on-scroll-up,
body.db-scrolling-down .db-hide-on-scroll-down {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
</style>

Add a Class to Your Module

To control which modules hide on scroll:

  • To hide a module when scrolling down, add the class: db-hide-on-scroll-down

  • To hide a module when scrolling up, add the class: db-hide-on-scroll-up

You can apply this class to any module, row, or section via the "Advanced > CSS ID & Classes > CSS Class" setting.

That’s It!

Now you have full control over which modules show or hide depending on the user’s scroll direction — a simple way to make your Divi site feel more intentional and polished.

Transform Your Pages with Divi Show / Hide Button!

Unleash the full potential of your Divi site with the Divi Show / Hide Button Module. Control the visibility of sections, rows, or modules with ease, create engaging tabs, and style your buttons just like any other Divi button. Perfect for keeping your pages clean and interactive.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

We may earn a commission when you visit links on our website.

0 Comments

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.

News