jQuery text loading animation

后端 未结 5 1171
隐瞒了意图╮
隐瞒了意图╮ 2021-01-05 01:22

Trying to make a text ... loading animation

here\'s where I stand: http://jsfiddle.net/aGfct/

I can get the ... to be added at 500 ms intervals, but then I w

5条回答
  •  再見小時候
    2021-01-05 02:04

    Just add this line at the end of your loop:

    i = (i === 3) ? 0 : i;
    

    That's just shorthand for saying 'if i is equal to 3, set it back to zero, else leave it as it is'. That should kick off your loop all over again until you set an exit condition.

    EDIT: Hold on, I didn't actually look at how you appended the .(sorry, can't get jsFiddle to run anything at the moment)! If you were to use the i reset as above, you'd really need to set the number of . characters equal to i with every iteration.

    EDIT 2: Looking again, you'd even need to take i into a closure to get its value at the time the setTimeout is declared, otherwise you'll get whatever value it is when setTimeout is executed, which is unpredictable. Basically, don't use this solution - use Jeff's! ;)

提交回复
热议问题