Created
July 17, 2013 15:21
-
-
Save theroux/6021572 to your computer and use it in GitHub Desktop.
Simple throttling function w/ jQuery
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 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