Last active
January 23, 2017 17:04
-
-
Save IbeVanmeenen/ec40e45584f2f786dc009eaf914c02c8 to your computer and use it in GitHub Desktop.
On Scroll
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
const appScroll = () => { | |
let latestKnownScrollY = 0, | |
ticking = false; | |
const _onScroll = () => { | |
latestKnownScrollY = window.pageYOffset; | |
_requestTick(); | |
}; | |
const _requestTick = () => { | |
if (!ticking) { | |
window.requestAnimationFrame(_update); | |
} | |
ticking = true; | |
}; | |
const _update = () => { | |
ticking = false; | |
const currentScrollY = latestKnownScrollY; | |
// Update functions here. Pass on currentScrollY as positionVariable | |
}; | |
// scroll mousewheel wheel | |
window.onscroll = (e) => { | |
_onScroll(); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment