2

After I have finished scrolling I want to trigger an event with the jQuery mousemove function.

The problem is that by scrolling the mousemove is triggered (http://docs.jquery.com/Tutorials:Mouse_Position#Tracking_mouse_position),

I want to trigger the event only when scrolling is over and I move the mouse for "real".

I am using a pretty neat solution to see when scrolling has stopped, so I want my mousemove-check to be done after that. jQuery scroll() detect when user stops scrolling

My idea is to read the X-coordinate and after scrolling only trigger the event if the Y-coordinate also changes, but I really would prefer if i could use something like delay() or setTimeout(), but none of those are working in combination...

Community
  • 1
  • 1
MMachinegun
  • 3,044
  • 2
  • 27
  • 44
  • well one way to do this (probably not the best way) is to bind/unbind mousemove on scrolling/stopping. Checking the coordinates is a good way to do this. Fire custom event at the end of the scroll, then check coordinates of the mouse to see when you should trigger the desired mousemove – Huangism Mar 08 '13 at 20:53
  • Thank you! The unbind-method works just great! I don't even have to check the coordinates for this :D – MMachinegun Mar 08 '13 at 21:05
  • So all I did was unbind mousemove on scroll _start_ and bind on scroll _end_ . I'm not sure what to do now with the question, for me it is answered :D, or do I just leave it like this, maybe somebody else will come up with a better answer? (because you replied in a comment I cannot check it :S) – MMachinegun Mar 08 '13 at 21:13

1 Answers1

1

One way to do this (probably not the best way) is to bind/unbind mousemove on scrolling/stopping. Checking the coordinates is a good way to do this. Fire custom event at the end of the scroll, then check coordinates of the mouse to see when you should trigger the desired mousemove

Maybe you can bind the mousemove all the time but set a flag, so when you are scrolling, set the flag to false so mousemove will not trigger and set it to true when scrolling stops, and trigger mousemove manually. This might work better than bind/unbind events all the time. Give this a try and see if it works out

Huangism
  • 16,278
  • 7
  • 48
  • 74
  • I'm not pretty sure what you ment exactly with _flag_, but what I did is, that before `unbind('mousemove')` I check if my variable is **not** false, then unbind the _mousemove_ and set _variable_ to false. This way unbind doesn't trigger as often... I notice a difference in Firefox. :) – MMachinegun Mar 12 '13 at 19:51
  • what I was suggesting is to avoid unbinding and rebinding altogether. Set flag=false when you scroll, and set flag=true when scroll stops. In your mousemove event handler, you check if flag=true or false, if true, then execute mousemove stuff, if false, do nothing. If you have time you can try it out but if not then you an use the current solution – Huangism Mar 12 '13 at 20:47