Javascript 环路在哪里?

Javascript 环路在哪里?,javascript,html,loops,Javascript,Html,Loops,我用这段代码为我的网页创建了一个打字旋转木马效果。我试图使旋转木马在到达数组中的最后一个字符串时停止。但我很难找到无限循环的位置 由于没有while或for循环,我不知道这是如何重复的。谁能给我指点一下吗 var TxtRotate=函数(el、旋转、周期){ this.toRotate=toRotate; this.el=el; this.loopNum=0; this.period=parseInt(period,10)| 2000; this.txt=“”; 这个。勾选(); this.

我用这段代码为我的网页创建了一个打字旋转木马效果。我试图使旋转木马在到达数组中的最后一个字符串时停止。但我很难找到无限循环的位置

由于没有while或for循环,我不知道这是如何重复的。谁能给我指点一下吗

var TxtRotate=函数(el、旋转、周期){
this.toRotate=toRotate;
this.el=el;
this.loopNum=0;
this.period=parseInt(period,10)| 2000;
this.txt=“”;
这个。勾选();
this.isDeleting=false;
返回;
};
TxtRotate.prototype.tick=函数(){
var i=this.loopNum%this.toRotate.length;
var fullTxt=this.toRotate[i];
如果(这是删除){
this.txt=fullTxt.substring(0,this.txt.length-1);
}否则{
this.txt=fullTxt.substring(0,this.txt.length+1);
}
this.el.innerHTML=''+this.txt+'';
var=这个;
var-delta=80;
如果(这是删除){
delta/=2;
}
如果(!this.isDeleting&&this.txt===fullTxt){
delta=这个周期;
this.isDeleting=true;
}else if(this.isDeleting&&this.txt==''){
this.isDeleting=false;
这个.loopNum++;
δ=200;
}
setTimeout(函数(){
那。勾选();
},三角洲);
};
window.onload=函数(){
var elements=document.getElementsByClassName('txt-rotate');
var-toRotate=elements[0]。getAttribute('data-rotate');
var period=elements[0]。getAttribute('data-period');
如果(旋转){
新的TxtRotate(元素[0],JSON.parse(toRotate),句点);
}
//注入CSS
var css=document.createElement(“样式”);
css.type=“text/css”;
css.innerHTML=“.txt rotate>.wrap{border right:0.08em solid#666}”;
document.body.appendChild(css);
返回;

};它使用某种自动“倒带”的时钟

勾选
的结尾是:

  setTimeout(function() {
    that.tick();
  }, delta);
这意味着当函数
勾选
结束时,它会安排在
增量
时间之后再次调用自己

看看您是否不熟悉这个(非常有用的)JavaScript函数

如果您想让它停止自身重复,只需使用延续条件将上述行包装在
If
块中即可


当在构造函数中创建对象TxtRotate时,第一次调用
tick

通过调用调用
setTimeout
的函数来启用“循环”,就像现在这样。啊,这很有意义!如果满足特定条件,是否有办法不调用下一个勾号?下一次调用的时间表是this
setTimeout
。只需将该呼叫(我在回答中复制的行)包装在某个
if
块中,您就有了结束条件!