Creates a debounced function throttled by requestAnimationFrame
.
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.
via npm
npm install raf-bounce --save
let rafBounce = require('raf-bounce');
window.addEventListener('resize', rafBounce(onResize));
function onResize() {
console.log('width', window.innerWidth);
console.log('height', window.innerHeight);
}