# How to pause an Animator with Mouseover?

I would like my Animator to pause when the mouse is not over it. For example, here it continues to update even when it's not moused-over:

Mouseover["not updating",
{Animator[Dynamic[n], {0, 100, 1}], Dynamic[n]}]


Is there a simple trick to pause it (keeping n static) until it is moused-over again?

• Can you give more specifics about what exactly you are trying to accomplish? There may be other solutions with manipulate or a user created animator which may or may not be acceptable depending on what you are trying to do. Apr 9 '20 at 18:37

The Animator object has a lot of internal controls that are a bit difficult to access. Another solution, if you don't need an Animator object, is to define your own.

mouseSlider[max_,rate_] := DynamicModule[{running, i = 0}, Mouseover[
running = False; "not running", running = True;
Dynamic[i += rate; {Slider[Mod[i, max], {0, max}], Mod[i, max]}]]]


• It's a good approach, but there's no obvious way (at least that I can see) to enforce an exact animation rate :(
– M.R.
Apr 9 '20 at 22:14
• I included a rate in the definition of mouseSlider. You could also use a Pause command. If you give more details about what you're trying to accomplish, I may be able to tailor my answer to better suit your situation Apr 10 '20 at 3:26
• Not my question, but just saying using an ++ increment has no connection to time
– M.R.
Apr 10 '20 at 3:38
• Are we looking at different things? You should see += rate (or += 0.01 in the animation) Apr 10 '20 at 3:57
• Yes I’m talk about frame rates in real time
– M.R.
Apr 10 '20 at 4:00

An extended comment. I tried with:

DynamicModule[{running = False, n = 0},
EventHandler[
Animator[Dynamic[n], {0, 100, 1},   AnimationRunning -> Dynamic[running]   ]
, { "MouseEntered" :> FEPrivateSet[running, True]
, "MouseExited" :> FEPrivateSet[running, False]
}
]
]


But at least on Win10 v12.1 the internal timer goes on and when on MouseExited and when it runs again it starts from the position it would have had without stopping.

EDIT: The solution

If we are less subtle it will work:

DynamicModule[{running = False, n = 0},
EventHandler[
Dynamic @ Animator[Dynamic[n], {0, 100, 1}, AnimationRunning -> running ]
, { "MouseEntered" :> FEPrivateSet[running, True]
, "MouseExited" :> FEPrivateSet[running, False]
}
]
]


It isn't completely FE-side anymore, evaluation of the whole Animator[...] goes back and forth, but at least it works.

• I've been running in circles, can't figure out why it keeps going internally... any other approaches? Apr 6 '20 at 18:03
• The scheduled task approach might be a bit heavy, especially if you try to make a grid of these things... are there no other dynamic magic tricks you know of to try here? Apr 7 '20 at 4:29
• @user5601 See the edit, I am not happy about it but it more acceptable than tasks.
– Kuba
Apr 8 '20 at 7:18
• This is nice, but if I make 50 of them the FE does the spinny wheel... also TableView, how might you get this to work in a TableView? Apr 8 '20 at 17:00