Skip to content

Instantly share code, notes, and snippets.

@theroux
Created July 17, 2013 15:21
Show Gist options
  • Save theroux/6021572 to your computer and use it in GitHub Desktop.
Save theroux/6021572 to your computer and use it in GitHub Desktop.
Simple throttling function w/ jQuery
var scrollTimeout;
var throttle = 50;
var scrollMessage = function (message) {
console.log(message);
};
$(window).on('scroll', function () {
if (!scrollTimeout) {
scrollTimeout = setTimeout(function () {
scrollMessage('I am scrolllllling with a throttled scroll!');
scrollTimeout = null;
}, throttle);
}
console.log('native scroll');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment