JSFiddle - React, Tailwind, and code Playground
by darcyclarke
JavaScript
var throttle = function (wait, func){
var ctx = function(e){
if(!window.timer){
window.timer = setTimeout(function(){
ctx.func();
clearTimeout(window.timer);
}, ctx.wait);
}
};
ctx.wait = wait;
ctx.func = func;
return ctx;
};
$(window).on('resize', throttle(500, function(){
console.log('I execute every 500 seconds while "resize" is firing');
}));
////////////