javascript - Execute code when scroll but each .5s -
i have situation when use mousewheel, dont want happend instantly, wait 50ms after can increment again.
var = 0; function dosomething() { += 1; console.log(i); }
need waiting time till can use mousewheel again.
can show or explain solution?
you can try timeouts (look @ example). or can use throttling/debouncing plugins this one
var = 0; function dosomething() { += 1; console.log(i); } var actiontimer = null; function delayedhandling(){ cleartimeout(actiontimer); actiontimer = settimeout(function() { dosomething(); }, 50); } $(window).on('dommousescroll', function(e) { if (e.originalevent.detail > 0) { delayedhandling(); } }) .on('mousewheel', function(e) { if (e.originalevent.wheeldelta < 0) { delayedhandling(); } });
Comments
Post a Comment