jquery - Dont execute javascript again for 1 second, even if trigger is re-triggered -
im detecting scrolling on page , executing code when use scrolls or down. problem code firing multiple times quickly. need code once executed not able execute again 1 second.
ideally execution disabled 1 second. if //do has fired, cant fire again 1 second , neither can //do else
note - know isnt reliable cross browser fine moment. doenst need work touchscreen scrolling.
$(document).ready(function(){ $('body').bind('mousewheel', function(e){ if(e.originalevent.wheeldelta /120 > 0) { //do } else{ //do else } }); }); ive tried using timeout function seems wait , fire multiple times, rather once:
settimeout(function() { //do event.stoppropagation(); }, 1000);
have debounce / throttle. there's popular jquery plug-in written ben alman provides sort of functionality. see underscore.
debounce or throttle? docs:
well, put simply: while throttling limits execution of function no more once every delay milliseconds, debouncing guarantees function ever executed single time (given specified threshhold).
Comments
Post a Comment