Created
January 3, 2013 18:38
-
-
Save livimonte/4445784 to your computer and use it in GitHub Desktop.
Event debouncer control.
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
var debouncer = function (func, pTimeout) { | |
var timeoutID, timeout = pTimeout || 200; | |
return function() { | |
var scope = this, args = arguments; | |
clearTimeout(timeoutID); | |
timeoutID = setTimeout(function() { | |
func.apply(scope, Array.prototype.slice.call(args)); | |
}, timeout); | |
}; | |
}; | |
//sample | |
$(window).resize(debouncer(function(e) { | |
console.log('window resized'); | |
})); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment