Skip to content

Instantly share code, notes, and snippets.

@samuelmaddock
Created August 17, 2016 16:35
Show Gist options
  • Save samuelmaddock/03409774005f894c49fea5abcc1bdf05 to your computer and use it in GitHub Desktop.
Save samuelmaddock/03409774005f894c49fea5abcc1bdf05 to your computer and use it in GitHub Desktop.
Scroll polling example
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