Throttles a function to run at most once every specified delay
2.0.0
The function to throttle
The minimum time between function calls in milliseconds
A throttled version of the passed function
// Throttle a scroll event handlerconst throttled_scroll = throttle(() => { console.log('Scroll event throttled');}, 1000);// Add the throttled function as an event listenerwindow.addEventListener('scroll', throttled_scroll);// Now, the console will log at most once every 1000ms during scrolling Copy
// Throttle a scroll event handlerconst throttled_scroll = throttle(() => { console.log('Scroll event throttled');}, 1000);// Add the throttled function as an event listenerwindow.addEventListener('scroll', throttled_scroll);// Now, the console will log at most once every 1000ms during scrolling
Remarks
Throttles a function to run at most once every specified delay
Version
2.0.0
Param: fn
The function to throttle
Param: delay
The minimum time between function calls in milliseconds
Returns
A throttled version of the passed function
Example