.repeat(events ,runNow ,callback)
- events –
- A string containing one or more event types, such as "click" or "submit" or custom event names.
- runNow –
- whether to start the loop immediately for the first time.
- Defaults to
- callback –
- a method that is called once per loop iteration.
- All current iteration counts/events (from inner-most to outer-most loop) are passed as arguments.
The beginning context for each loop iteration depends on the usage of
Examples with the event-triggered loop
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.
$('.example button').repeat('click').prev() .wait(500).addClass('blink') .wait(300).removeClass('blink');