- timeout –
- the number of milliseconds to wait for.
- A value of
0means the shortest possible timeout that the browser provides via
- callback –
- a method that is called once after the timeout.
- All current iteration counts/events (from inner-most to outer-most loop) are passed as arguments.
Examples with waiting for timeout
By using .toggleClass() the CSS class switches from being added and removed after every timeout.
In this example a repeated timeout of 700 milliseconds is used.⇒
See also another example for the same task using an interval loop instead.
The whole method chain
is repeated once per second.
In this code the object
Date is used as a callback function to get a simple example for changing text.
Menu navigation is frustrating when the submenu closes immediately on mouseleave, because sometimes the mouse pointer moves few pixels unintended. That's why we want to build in timeouts on mouseenter and mouseleave to show/hide the corresponding submenu.
With jquery-timing this is just two lines:⇒
With the concatenation of two .wait()s we achieve a single short blink.
Instead of attaching an event handler explicitly we start an infinite event loop for the "click" event. Repeat loops are always sequential, i.e. the next iteration can start only if the previous one ended. You can see this behavior when double- or triple-clicking the button.⇒
These 25 boxes shall be animated as falling down with each button click.A helper function is necessary to animate them in reverse order:
Try clicking on that button multiple times during animation. With .stop(true,true) and .unwait() all animations are reset at the beginning.⇒