Skip to content

Instantly share code, notes, and snippets.

@oobleck
Created March 9, 2014 03:02
Show Gist options
  • Save oobleck/9442357 to your computer and use it in GitHub Desktop.
Save oobleck/9442357 to your computer and use it in GitHub Desktop.
jQuery: Debounce method in jQ namespace. See comments for original script
// Source: http://stackoverflow.com/a/4298672/2573965
;(function($) {
// http://en.wikipedia.org/wiki/Debounce#Contact_bounce
// Runs func after the calling event trigger completes. Useful for window resizes, etc.
$.fn.debounce = function debouncer( func , timeout ) {
var timeoutID , timeout = timeout || 200;
return function () {
var scope = this , args = arguments;
clearTimeout( timeoutID );
timeoutID = setTimeout( function () {
func.apply( scope , Array.prototype.slice.call( args ) );
} , timeout );
}
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment