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, 

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

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

Latest Posts

Enable Swipe Navigation in the Divi Gallery Lightbox

Enabling swipe navigation in the Divi Gallery module's lightbox allows users to seamlessly browse through gallery images by swiping left or right, creating a more interactive and mobile-friendly experience. This functionality can significantly improve user engagement...

Disable Slide-In Animation for Divi Gallery Grid Images

Control how images appear in your Divi Gallery module by toggling the slide-in animation effect for grid layouts. Disabling the slide-in animation allows gallery images to load instantly and appear statically, providing a faster and distraction-free browsing...

Control Image Count Display in Divi Gallery Lightbox

Displaying or hiding the image count in the Divi Gallery module’s lightbox can help customize the user experience, depending on whether you want to give visitors an indication of gallery progress or prefer a cleaner, distraction-free view. The ability to toggle this...

Hide Gallery Image Titles in the Divi Lightbox Overlay

Displaying image titles in the lightbox overlay of the Divi Gallery module can sometimes be distracting or unnecessary, depending on your website’s design and user experience goals. Hiding these titles creates a cleaner and more focused viewing experience for visitors...

Customize Divi Gallery Module Pagination with Custom Text and Icons

Enhancing the navigation experience in your Divi Gallery module can make your galleries more intuitive and visually appealing for visitors. By replacing the default previous and next pagination links with your own text and icons, you can better align the gallery...

Random Posts