Last active
May 9, 2016 18:38
-
-
Save kellyrmilligan/aba9dd155ed77dc579faa8d022ec65a6 to your computer and use it in GitHub Desktop.
scroll cache module and raf loop
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
export default { | |
scrollY: '', | |
getScrollY() { | |
return (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop; | |
}, | |
init() { | |
window.addEventListener('scroll', (e) => { | |
this.scrollY = this.getScrollY(); | |
}); | |
this.scrollY = this.getScrollY(); | |
} | |
} | |
function componentInViewport(ts) { | |
let rootNode = self.getDOMNode(); | |
if(isOnScreen(rootNode, 600)) { | |
self.setState({ | |
componentInViewport: true | |
}); | |
if (self.onComponentInViewport) { | |
self.onComponentInViewport(); | |
} | |
window.cancelAnimationFrame(self.animationFrameId); | |
} else { | |
self.animationFrameId = window.requestAnimationFrame(componentInViewport); | |
} | |
} | |
this.animationFrameId = window.requestAnimationFrame(componentInViewport); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment