.until(count ,loopContext)
- count –
number
- the number of iterations to run.
- Values less than
1
result in a single iteration. - loopContext –
boolean
, optional - 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.
Usage pattern
Examples with loop countdown
Example #4: blinking a given number of times on click
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($).
⇒That text blinks two times after clicking .
Example #5: create dynamic tables with instant loops
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:
⇒
Example #8: simple progress indicator with text
The text dots will go on and on in this example. Of course in a real use case it would be stopped using .unrepeat().
⇒Still processing
Example #9: generating password with fake progress
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,e.g. ,
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.
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.
⇒ Example #20: ruler with animation
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:
⇒