Bouncer: a Javascript plugin to throttle and debounce callbacks easily.
Install with Bower
bower install Bouncer
Or by cloning this repository.
The plugin can be used with or without jQuery.
The syntax is like so:
namespace.option(delay,callback,runBefore);
- namespace: use
$
with jQuery, usebouncer
without - option:
throttle
ordebounce
- delay: number - use 0 or greater in milliseconds
- callback: your callback function, eg an ajax call
- runBefore: for
debounce
, run yourcallback
before or after thedelay
Use the $
namespace
$.throttle(500,callback);
$.debounce(500,callback[,true]);
$("#foo").click($.debounce(500,function() {
// My ajax callback
});
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);