Created
August 12, 2015 10:09
-
-
Save cladley/9cfcff27a3374eec2b2f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var latestKnownScrollY = 0, | |
| ticking = false; | |
| function onScroll(){ | |
| latestKnownScrollY = window.scrollY; | |
| requestTick(); | |
| } | |
| function requestTick(){ | |
| if(!ticking){ | |
| requestAnimationFrame(update); | |
| } | |
| ticking = true; | |
| } | |
| function update(){ | |
| // reset the tick so we can | |
| // capture the next onScroll | |
| ticking = false; | |
| var currentScrollY = latestKnownScrollY; | |
| // console.log("current Scroll : " + currentScrollY); | |
| console.log(`current scroll ${currentScrollY}`); | |
| // do whatever dom updates. Read first in a batch | |
| // then write in a batch if possible | |
| } | |
| window.addEventListener('scroll', onScroll, false); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment