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.

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

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.

Latest Posts

Top (or Bottom) Align Divi Icon List Module Icons

When Icon List items wrap onto multiple lines, the default icon alignment can make the icon appear vertically centered next to the text, which may look unbalanced or harder to scan. Setting the icons to align at the top creates a cleaner, more consistent...

Make Divi Button Modules Full Width with Centered Content

This configuration makes a Divi button stretch to the full width of its container while keeping its label neatly centered, creating a bold, edge-to-edge call-to-action. You might want this for hero sections, pricing tables, or any layout where a standard-sized button...

Fix the Flickr Typo in the Divi Social Media Follow Module

Sometimes it's the small things that make the difference... there is a minor typo in the Divi Social Media Follow module that was present in Divi 4, and (currently) remains in Divi 5. Specifically, the tooltip for Flickr is misspelled as "Flikr". Here's how to fix...

Add a Frosted-Glass Background Blur in Divi

Give your Divi layouts a polished, glassmorphism look by blurring the content behind a semi‑transparent Divi section, row or module. This effect enhances readability over busy or textured backgrounds while preserving the visual impact of your imagery and layout. In...

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, 

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 *.