I have a jQuery function that is running on setInterval();
What I want to do is stop the interval when I hover over the div being displayed, and once I hover off the div, start the interval again (aka continue cycling through the divs).
any idea on how to do this in the simplest form possible?
Thanks!
Amit
There’s Reigel’s way, which works a treat, or of course just set a flag that your function checks, only doing its processing if the flag isn’t set. Particularly convenient if there’s already some indication of hovering that you can use (e.g., as opposed to an actual dedicated flag), if you want to do this for several intervals, etc.
and to hook that up, basically:
Note that those don’t declare their own
hovering, as Amit’s comment below does; they use thehoveringdeclared in the enclosing scope.More thorough example:
I used a counter here instead of a simple flag, but that’s me being paranoid.
HTML:
JavaScript (ticktock.js):