raf-bounce
v1.0.2
Published
Creates a debounced function throttled by requestAnimationFrame
Downloads
1
Readme
RafBounce
Creates a debounced function throttled by requestAnimationFrame
.
Why
Useful for implementing behavior that should only happen when the browser is ready, and after a repeated action has completed.
Instead of forcing a browser repaint when the browser isn't ready (set intervals), this library will perform actions as fast as the browser allows.
Another requestAnimationFrame
call will not be made until the last execution has finished.
Installation
via npm
npm install raf-bounce --save
Example
let rafBounce = require('raf-bounce');
window.addEventListener('resize', rafBounce(onResize));
function onResize() {
console.log('width', window.innerWidth);
console.log('height', window.innerHeight);
}