@lagrange/animator
Version:
This library helps making parallax animations on scroll. It is built with performance in mind, as it doesn't need to relayout or paint to operate.
17 lines (16 loc) • 403 B
JavaScript
/*eslint-disable*/
export default function(func, wait, immediate) {
let timeout;
return function() {
const context = this;
const args = arguments;
const later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
}