and more available on mobile, tablet and desktop.
- inThrottle = false, limit);
+ }
+ }
+ }
+ // scrolling event with throttling
function scrollHandler() {
- // scroll hint
- let scroll = document.scrollingElement.scrollTop;
+ // cache scroll value to avoid repeated DOM access
+ const scroll = document.scrollingElement.scrollTop;
// hide arrow when needed
if (scroll >= arrowTreshold && arrow) {
@@ -32,6 +42,9 @@
}
}
+ // throttle scroll handler to run at most every 100ms
+ document.addEventListener("scroll", throttle(scrollHandler, 100));
+
// initialize scroll hint
showScrollHint(3);
}