28
Views
2
Comments
Solved
How can I hide header when scrolling down and show header when scrolling up?
Question
Application Type
Reactive
Service Studio Version
11.55.29 (Build 64246)

I am trying make the header hide when scrolling down and show when scrolling up but it is not working. Is there something wrong with my code?


This is the javascript on the OnReady of my layout web block:


This is my CSS:



2026-01-28 16-57-48
Mihai Melencu
Champion
Solution

Hi @eli010101 ,

Your CSS classes are not actually used. The class for the header is ".header". I tested and the following CSS and JS works:

.header {

  position: fixed;

  top: 0;

  left: 0;

  width: 100%;

  z-index: 9999;

  transition: transform 0.3s ease;

}


.header.appheader--hidden {

  transform: translateY(-100%);

}


JS:

var lastScrollTop = 0;

  var header = document.querySelector('.header');

  if (!header) return;


  var scrollEl =

       document.querySelector('.screen-container[scroll]')

    || document.querySelector('.active-screen.screen-container')

    || document.querySelector('.screen-container')

    || window;


  function getScrollTop() {

    return scrollEl === window

      ? (window.pageYOffset || document.documentElement.scrollTop)

      : scrollEl.scrollTop;

  }


  scrollEl.addEventListener('scroll', function() {

    var st = getScrollTop();


    if (st > lastScrollTop && st > 50) {

      if (!header.classList.contains('appheader--hidden')) {

        header.classList.add('appheader--hidden');

      }

    } else {

      if (header.classList.contains('appheader--hidden')) {

        header.classList.remove('appheader--hidden');

      }

    }


    lastScrollTop = Math.max(0, st);

  });

Also make sure your header is not fixed from the outsystems property: 

You can check the attached OML for reference.

TestScroll1.oml
UserImage.jpg
eli010101

Hi @Mihai Melencu

Thank you, it worked.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.