1.0.3 • Published 8 years ago

throttled-debounce v1.0.3

Weekly downloads
2
License
ISC
Repository
github
Last release
8 years ago

Throttled-Debounce

Throttled-Debounce is a library designed to limit the call rate of a function. It allows to use a throttling & debouncing mechanism combined.

Usage

var controlFunc = (options) => {
    var event = options.arguments[0];
    if(options.callCount === 1){
        options.timing = Date.now();
        options.element = event.target;
    } else {
        //change of element
        if(options.element !== event.target){
            options.split(); //force bounce
        }
    }
};

var callback = (options) => {
	options.timing = Date.now() - options.timing;
    console.log(options);
};

var options = {
    callback: callback,
    controlFunc: controlFunc,
    maxDelay: 3000,
    throttleWait: 500
};

window.scroll_handler = throttledDebounce(options);
document.addEventListener('scroll', window.scroll_handler, true);

window.scroll_handler.cancel(); //stop fire events
window.scroll_handler.resume(); //resume

window.scroll_handler.bounce(); //force bounce
1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago