// Created on savesnippets.com ยท https://savesnippets.com/7PIrApzB080u0m function throttle(fn, limit = 300) { let lastRun = 0; return function (...args) { const now = Date.now(); if (now - lastRun >= limit) { lastRun = now; return fn.apply(this, args); } }; } // Usage const onScroll = throttle(() => { console.log('scroll Y:', window.scrollY); }, 200); window.addEventListener('scroll', onScroll);