Skip to content

Instantly share code, notes, and snippets.

@AshKyd
Created January 17, 2014 01:40
Show Gist options
  • Save AshKyd/8467030 to your computer and use it in GitHub Desktop.
Save AshKyd/8467030 to your computer and use it in GitHub Desktop.
Is the document scrolling right now? Prevent jank by pausing stuff while the user's trying to navigate the document.
var isScrolling = false;
$(document).ready(function(){
var scrollTimeout = false;
var scrollTimeoutFn = function(){
isScrolling=false;
scrollTimeout = false;
}
jQuery(window).bind('scroll', function(){
isScrolling = true;
if(scrollTimeout){
window.clearTimeout(scrollTimeout);
}
scrollTimeout = window.setTimeout(scrollTimeoutFn,300);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment