Created
August 17, 2016 16:35
-
-
Save samuelmaddock/03409774005f894c49fea5abcc1bdf05 to your computer and use it in GitHub Desktop.
Scroll polling example
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 element = $('.element-with-scrolling'); | |
// don't do this | |
element.attachEventListener('scroll'); | |
// do this instead | |
window.requestAnimationFrame(poll); | |
var pollScrollPos = function () { | |
var scrollPos = element.scrollLeft; | |
// ... | |
window.requestAnimationFrame(pollScrollPos); | |
}; | |
pollScrollPos = pollScrollPos.bind(contextExample); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment