【发布时间】:2018-10-02 08:37:05
【问题描述】:
我想知道为什么这段代码会导致我的浏览器崩溃:
while (true) {
$('.selector')
.animate({ 'bottom': '30px' }, 500)
.animate({ 'bottom' : '20px' }, 500);
}
并且这个其他代码有效(没有 true 作为条件)
var a = 0;
while (a < 1000) {
$('.selector')
.animate({ 'bottom': '30px' }, 500)
.animate({ 'bottom' : '20px' }, 500);
a++;
}
如果我敢自己回答这个问题,我会说第二个代码填充了一个包含 1000 个操作的队列,并在第一个代码从未完成并导致浏览器崩溃时停止。
我需要它是无限的,但在动画完成之前不会进行下一次迭代。我在这里和那里玩stop();,但它没有成功。
【问题讨论】:
-
第一个循环中没有
break。
标签: javascript while-loop conditional-statements