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?

http://jsbin.com/lisozuyami/1/edit?html,js,console,output

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

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -