jquery mousewheel: detecting when the wheel stops?

Viewed 39223

I'm using Jquery mousewheel plugin and I would like like to be able to detect when the user has finished using the wheel. Similar functionality as the stop: event in the draggable stuff. Can somebody point me to the right direction?

5 Answers

Nick Craver's answer works fine. But it will cause a small delay (of 250ms) to perform the // do something. A better option would be to execute your codes right away and wait delayms before catching further events.

To do this, use a global variable say processing, initialize it with false and toggle it's value before and after code execution.

window.processing = false;
$("#myElem").mousewheel(function() {
   if (processing === false) {
     processing = true;
     // do something
     setTimeout(function() {
       processing = false;
     }, 250)); // waiting 250ms to change back to false.
   }
 });
Related