Skip to content

Instantly share code, notes, and snippets.

@larsmqller
Created July 15, 2019 08:34
Show Gist options
  • Save larsmqller/f63f21a7dfb88b589176ae0eb1c12791 to your computer and use it in GitHub Desktop.
Save larsmqller/f63f21a7dfb88b589176ae0eb1c12791 to your computer and use it in GitHub Desktop.
60FPS onscroll event listener
(function() {
var lastScrollY = 0;
var ticking = false;
var update = function() {
// do your stuff
ticking = false;
};
var requestTick = function() {
if (!ticking) {
window.requestAnimationFrame(update);
ticking = true;
}
};
var onScroll = function() {
lastScrollY = window.scrollY;
requestTick();
};
$(window).on('scroll', onScroll);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment