.wait(timeout ,callback)
- timeout –
number
- the number of milliseconds to wait for.
- A value of
0
means the shortest possible timeout that the browser provides viawindow.setTimeout()
. - callback –
function(count…)
, optional - 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.
Usage pattern
Examples with waiting for timeout
Example #2: repeated blinking with iterated timeouts
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.
⇒This is a blinking text.
See also another example for the same task using an interval loop instead.
Example #7: clock display with one short blink per second
The whole method chain .text(Date).addClass('blink').wait(100).removeClass('blink')
is repeated once per second.
Here is a clock: --.
In this code the object Date
is used as a callback function to get a simple example for changing text.
Example #10: fading submenus with user friendly timeouts
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:
⇒Example #14: wait a timeout after each click before blinking
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.
⇒That text blinks half a second after hitting .
Example #18: falling little boxes
This example first creates 25 little boxes with an inline definition: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.
⇒