Remove position sticky khi scroll 1 đoạn

(function() {
  if (window.innerWidth > 767) return;

  let hasAddedClass = false;

  function checkScroll() {
    const scrollY = window.scrollY || window.pageYOffset;
    const triggerPoint = 300;

    if (scrollY >= triggerPoint && !hasAddedClass) {
      document.body.classList.add('remove-sticky');
      hasAddedClass = true;
    } else if (scrollY < triggerPoint && hasAddedClass) {
      document.body.classList.remove('remove-sticky');
      hasAddedClass = false;
    }
  }

  let ticking = false;
  window.addEventListener('scroll', function() {
    if (!ticking) {
      window.requestAnimationFrame(function() {
        checkScroll();
        ticking = false;
      });
      ticking = true;
    }
  });

  checkScroll();
})();

 

Buy me a coffee