Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

debounce js

const debounce = (fn, delay) => {
  let timer;
  return function () {
    clearTimeout(timer);
    timer = setTimeout(fn, delay);
  };
};

// Example
let count = 0;
const increaseCount = (num) => {
  count += num;
  console.log(count);
};

window.addEventListener('scroll', debounce(increaseCount.bind(null, 5), 200));
Source by gist.github.com #
 
PREVIOUS NEXT
Tagged: #debounce #js
ADD COMMENT
Topic
Name
2+7 =