Skip to content

Instantly share code, notes, and snippets.

@IbeVanmeenen
Last active January 23, 2017 17:04
Show Gist options
  • Save IbeVanmeenen/ec40e45584f2f786dc009eaf914c02c8 to your computer and use it in GitHub Desktop.
Save IbeVanmeenen/ec40e45584f2f786dc009eaf914c02c8 to your computer and use it in GitHub Desktop.
On Scroll
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