On some condition I want to cancel onmousemove event when mouse goes down, for example. Is it possible to determine the direction of onmousemove event? jQ or JS is Ok.
I have drag’n’drop elements. The user drags the elenment up. If, for example, the bottom of the element reaches some position in the document (i.e. 500px from the top of the document) the onmousemove stops. And if the user will try to drag the element up again the function will not start. Only drag down will be possible for this element. So I thought it would be quite easy to do it by catching the direction of the mousemove event. But it seems there’s no such kind of standard properties.
You can save the position of the last
mousemoveevent to compare to the current position:Here is a demo: http://jsfiddle.net/Dv29e/
Update
You can also throttle the
mousemoveevent to get more of a general idea where the mouse has moved:This will only check the cursor's position against it's past position if:
mousemove_okvariable is set totruewhich is done every half second.Here is a throttled demo: http://jsfiddle.net/Dv29e/4/