1.0.0 • Published 9 years ago
js-bouncer v1.0.0
Bouncer
Bouncer: a Javascript plugin to throttle and debounce callbacks easily.
Installation
Install with Bower
bower install Bouncer
Or 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, 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
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
9 years ago