Skip to content

Instantly share code, notes, and snippets.

@JMayfield
Last active October 21, 2020 17:57
Show Gist options
  • Save JMayfield/37f03df918336b11985f0bbf5acfd4e7 to your computer and use it in GitHub Desktop.
Save JMayfield/37f03df918336b11985f0bbf5acfd4e7 to your computer and use it in GitHub Desktop.
A gentle way to hook up to the jQuery scroll event while maintaining a reasonable frame-per-second scroll rate.
var scrolled = false;
$(window).scroll(scrollEvents);
function scrollEvents() {
scrolled = true;
}
setInterval(function() {
if(didScroll) {
// Execute scroll events, animations, etc. here
didScroll = false;
}
}, 200);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment