Created
October 1, 2013 10:48
-
-
Save roman01la/6776766 to your computer and use it in GitHub Desktop.
How to handle scroll event properly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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