views:

29

answers:

1

Hi there! 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?

+2  A: 

There's no "stop" event here really - you get an event when you do scroll, so every time a mousewheel event happens the event is triggered...when there's nothing you'll get no events and your handler won't be firing.

You ca however detect when the user hasn't used it in say 250ms, like this:

$("#myElem").mousewheel(function() {
  clearTimeout($.data(this, 'timer'));
  $.data(this, 'timer', setTimeout(function() {
     alert("Haven't scrolled in 250ms!");
     //do something
  }, 250));
});

You can give it a try here, all we're doing is storing the timeout on each use in using $.data(), if you use it again before that time runs out, it gets cleared...if not then whatever code you wanted to run fires, the user has "finished" using their mousewheel for whatever period of time you're testing for.

Nick Craver
Yeah, I was thinking about something similar. I will give it a try.Thanks a lot Nick.
Moustard
@Moustard - Welcome :) If it works out be sure to accept answers on your questions ;)
Nick Craver