1.0.0 • Published 10 years ago
js-bouncer v1.0.0
Bouncer
Bouncer: a Javascript plugin to throttle and debounce callbacks easily.
Installation
Install with Bower
bower install BouncerOr by cloning this repository.
How to use
The plugin can be used with or without jQuery.
The syntax is like so:
namespace.option(delay,callback,runBefore);- namespace: use
$with jQuery, usebouncerwithout - option:
throttleordebounce - delay: number - use 0 or greater in milliseconds
- callback: your callback function, eg an ajax call
- runBefore: for
debounce, run yourcallbackbefore or after thedelay
With jQuery
Use the $ namespace
$.throttle(500,callback);
$.debounce(500,callback[,true]);$("#foo").click($.debounce(500,function() {
// My ajax callback
});Plain Javascript
Use the bouncer namespace
bouncer.throttle(500,callback);
bouncer.debounce(500,callback[,true]); document.getElementById('foo')addEventListener('click', bouncer.debounce(500,function(){
// My ajax callback
}),false);1.0.0
10 years ago