Created
March 9, 2014 03:02
-
-
Save oobleck/9442357 to your computer and use it in GitHub Desktop.
jQuery: Debounce method in jQ namespace. See comments for original script
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
// 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