Created
September 16, 2014 13:14
-
-
Save kanakiyajay/9f89253fb1d3cdae00db to your computer and use it in GitHub Desktop.
Throttle: Call a function only once every few milliseconds. Important for scroll events, or when a function is called multiple times.
This file contains 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
function throttle(delay, callback) { | |
var previousTime = new Date().getTime(); | |
return function() { | |
var newTime = new Date().getTime(); | |
if ((newTime - previousTime) > delay) { | |
previousTime = newTime; | |
callback.apply(null, arguments); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment