Skip to content

Instantly share code, notes, and snippets.

@roman01la
Created October 1, 2013 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roman01la/6776766 to your computer and use it in GitHub Desktop.
Save roman01la/6776766 to your computer and use it in GitHub Desktop.
How to handle scroll event properly
function updatePage() {
// do stuff
scheduleAnimationFrame = false;
}
function onScroll() {
lastScroll = window.scrollY;
if (scheduleAnimationFrame)
return;
scheduleAnimationFrame = true;
requestAnimationFrame(updatePage);
}
window.addEventListener('scroll', onScroll, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment