I
I
IIIu6ko2021-07-15 11:45:48
JavaScript
IIIu6ko, 2021-07-15 11:45:48

How to make the scroll event not fire?

Good afternoon. I have a header that adds the header--fixed class when scrolling.

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

window.addEventListener('scroll', () => {
  if (window.pageYOffset >= 1) {
    header.classList.add('header--fixed');
  } else {
    header.classList.remove('header--fixed');
  }
});


When opening a modal window, the scroll is removed and the scroll event fires. As a result, window.pageYOffset shows that it is at the very top of the page and the header--fixed class is removed.
How can I make the event not fire under such conditions? Or mb some kind of check can be done?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question