- count –
- the number of iterations to run.
- Values less than
1result in a single iteration.
- loopContext –
- if true then the current jQuery context starts the next loop iteration. Otherwise the original context from the .repeat() call is used for each iteration.
- Defaults to false.
Examples with loop countdown
We repeat .toggleClass() for an even number of times, so the class "blink" is absent again when the repeat loop finishes.
Remark that the click handler is assigned directly in the invocation chain using .click($).⇒
Imagine you want to add very many table rows automatically so you can fill them with dynamic content.
E.g. a 30 x 200 sized table. Then you need only one callback method creating each cell. The rest is done via a single jQuery chain:
The text dots will go on and on in this example. Of course in a real use case it would be stopped using .unrepeat().⇒
Of course generating a random password is done in less than a millisecond. But you want to simulate heavy computational things going on – just for a nice user experience.Given that you have a method which adds one random character at a time to an input value,
then you can use that to build our password generator.
So what happens here?
- First we interrupt any possibly ongoing password generation by using .unrepeat().
- We clear the current password value and add a nice animated gif in the background with .val('').addClass('load').
- Now we repeatedly add a new random character with .repeat(200).val(addRandomChar).
- After doing so for 10 times we stop and then remove our CSS class with .until(10).removeClass('load').
Try out clicking multiple times on that button. You will see, that the ongoing animation is always stopped before starting over.
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.⇒
This example shows how to create a ruler with an animated selection mark.
Each time the user clicks on one of the tick marks the button moves up to this mark. During its animation all underlying ticks get highlighted when the button flies by.
This is the complete code:⇒