How to modify on_mouse_move function

J

john_woo

Hi,

If what I want from the on_mouse_move function is, trigger another
function in two case:
1. when the mouse holds at same position for 1 second;
2. when the mouse fully stop;

in other cases (when mouse keeps moving) don't trigger that function.

Can any one tell how to implement this?
 
E

Evertjan.

john_woo wrote on 29 dec 2007 in comp.lang.javascript:
Hi,

If what I want from the on_mouse_move function is, trigger another
function in two case:
1. when the mouse holds at same position for 1 second;

With each mousmove detected start a setTimeout delay of 1 sec, after
resetting the last one.

If the delay fully times out, start your function.
2. when the mouse fully stop[s?];

What is that, you will have to define that, no trigger for how long,
three days perhaps?

It is the same as above.
in other cases (when mouse keeps moving) don't trigger that function.

Can any one tell how to implement this?

Yes, it is elementary.
 
J

john_woo

john_woo wrote on 29 dec 2007 in comp.lang.javascript:



With each mousmove detected start a setTimeout delay of 1 sec, after
resetting the last one.

If the delay fully times out, start your function.

you won't be able to tell during that 1 second, whether the mouse
stays in same position (namely X/Y never changed, the case that mouse
moves away and move back doesn't count);
The question is clear that triggering another function only when the
mouse stays for 1 second.
 
E

Evertjan.

john_woo wrote on 30 dec 2007 in comp.lang.javascript:
you won't be able to tell during that 1 second, whether the mouse
stays in same position (namely X/Y never changed, the case that mouse
moves away and move back doesn't count);

Wrong, the mouse has moved if an onmousemove event was triggered.
Testing where the mouse is in x/y is not necessary nor usefull.

The question is clear that triggering another function only when the
mouse stays for 1 second.

Indeed.
 
J

john_woo

john_woo wrote on 30 dec 2007 in comp.lang.javascript:





Wrong, the mouse has moved if an onmousemove event was triggered.
Testing where the mouse is in x/y is not necessary nor usefull.

<http://www.w3schools.com/jsref/jsref_onmousemove.asp>

The question is not about the on_mouse_move definition. say mouse
moves from

A -> B (move slowly) -> C (here stop for 1 second then continue to
move) -> D, and fully stops at D

thus the movement triggers event at A, B and C. my question was, I
wanted to trigger another function only when the mouse at C, not at B
nor D;
the setTimeout is used to delay action, regardless of whether mouse
stop 1 second then move again or keep moving without stop.

John
 
E

Evertjan.

john_woo wrote on 30 dec 2007 in comp.lang.javascript:
The question is not about the on_mouse_move definition. say mouse
moves from

A -> B (move slowly) -> C (here stop for 1 second then continue to
move) -> D, and fully stops at D

thus the movement triggers event at A, B and C. my question was, I
wanted to trigger another function only when the mouse at C, not at B
nor D;

No that was not the Q.

The Q was:
the setTimeout is used to delay action, regardless of whether mouse
stop 1 second then move again or keep moving without stop.

No, you are looking at my programming advice the wrong way.

I'll refrase:

Every time the mouse moves, the setTimeout is reset and restarted.
Only if there is no movement for one second, setTimeout times out and
your function is executed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top