if the mouse stop above a div I need call a specific function, but I need call it all time..
I've tried .mouseover() and .hover() but these work just when the mouse is moving
how keep call the function all time???
if the mouse stop above a div I need call a specific function, but I need call it all time..
I've tried .mouseover() and .hover() but these work just when the mouse is moving
how keep call the function all time???
.hover() works for me whenever the mouse is hovering. It doesn't have to keep moving. Just tried it for 2 minutes no problem. Nothing mentioned here.
You probably don't want to keep firing the same function. this would be murder on the client's processor. maybe a timeout and recheck?
The setInterval function allows you to arrange for a function to be called repeatedly according to a fixed schedule:
var intervalKey = setInterval(yourFunction, milliseconds);
The "milliseconds" value tells the system how long to wait between calls. The cycle can be cancelled by calling
clearInterval(intervalKey);
What you would do would be to set a flag on the "mouseover" event, and then clear the flag in the "mouseout" handler. The "mouseover" handler would also start the interval timer. The timer function would check the flag to determine whether it should stop (flag no longer set), and cancel itself.
If you want to track the mouse movement within the box, you'll need to use mousemove() rather than mouseover() or hover().
See a good example here: http://www.lbstone.com/reference/jquery/follow_mouse.html
If you want exactly what you asked for in the question -- ie continually firing the same function over and over while the mouse is over a div, you'll still need hover() or mouseover(), but when they fire, you'll need to call setTimeout() to start the repeating function, and within that function, check if the mouse is still in the <div> and if so, repeat the setTimeout() call. (alternatively, use setInterval() to start the sequence and clearInterval() to stop it; same end result)
It's quite a complex operation (and fraught with possible issues), so I'd avoid doing it if at all possible. What is it that you're trying to achieve by doing this (there's a very good chance theres a better way to do it! ;-))