0

i am using mousewheel event. i want something like function "start" and "stop". the start function is going to execute whenever mouse wheel starts and stop function going to execute whenever mousewheel stops ?

is there any callback function in mousewheel event in jquery ?

var matched = jQuery.uaMatch(navigator.userAgent);
var eventName = matched.browser.toLowerCase() == "mozilla" ? "DOMMouseScroll" : "mousewheel";  
$(this.element).on(eventName, this.chartMouseWheel);



  chartMouseWheel:function()
{

 start:
{
},
stop:
{
},

}

i need to do some operation whenever mouse wheel starts and do some other operation when mouse wheel ends ?

how can i do this ?

Thanks,

Siva

SivaRajini
  • 7,225
  • 21
  • 81
  • 128

2 Answers2

2

Here you can see how to intercept mousewheel up and down: http://jsfiddle.net/ykv5S/9/

code:

$('#test').bind('mousewheel', function(event, delta) {
    var dir = delta > 0 ? 'Up' : 'Down';
    $("#output").html(dir)
});

now I think you need to add some step to know the mouse speed and get when is == 0


Found a similar question on SO: have a look here, maybe is useful:

jquery mousewheel: detecting when the wheel stops?

Community
  • 1
  • 1
BeNdErR
  • 17,471
  • 21
  • 72
  • 103
  • sorry am not asking about mousewheel up and down. am asking about mousewheel start and stop – SivaRajini May 31 '13 at 09:40
  • have a look here, maybe is useful for your problem. http://stackoverflow.com/questions/3515446/jquery-mousewheel-detecting-when-the-wheel-stops – BeNdErR May 31 '13 at 09:41
1

There's no direct function in jQuery for that.

That's what I use :

window.addEventListener("mousewheel", mousewheel, false); // chrome
window.addEventListener("DOMMouseScroll", mousewheel, false); // firefox

(mousewheel is the name of a function)

If you want the wheel to be handled only when the mouse pointer is over an element, do this :

$myElement.mouseenter(function() {
    window.addEventListener("mousewheel", mousewheel, false); // chrome
    window.addEventListener("DOMMouseScroll", mousewheel, false); // firefox
}).mouseleave(function() {
    window.removeEventListener("mousewheel", mousewheel, false);// chrome
    window.removeEventListener("DOMMouseScroll", mousewheel, false);// firefox
});

Demonstration

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758