这段JS代码如何让它只执行一次就停止

目前的代码是无间断且无缝滚动的,怎么让它只执行一次,就停止。 $.fn.extend({ Scroll:function(opt,callback){ if(!opt) var opt={}; var _this=this.eq(0).find("ul:first"); var lineH=_this.find("li:first").height(), line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10), speed=opt.speed?parseInt(opt.speed,10):500, timer=opt.timer?parseInt(opt.timer,10):2000; if(line==0) line=1; var upHeight=0-line*lineH; scrollUp=function(){ _this.animate({ marginTop:upHeight },speed,function(){ for(i=1;i<=line;i++){ _this.find("li:first").appendTo(_this); } _this.css({marginTop:0}); }); } _this.hover(function(){ clearInterval(timerID); },function(){ timerID=setInterval("scrollUp()",timer); }).mouseout(); } }) $(".top_txt").Scroll({line:2,speed:500,timer:1000}); 页面代码 第1行 第2行 第3行 第4行 第5行 第6行 想让它停在第最后两行就不再动了

第1个回答  2019-07-16
js本身就只执行一次啊?除非你用setinterval函数来循环调用
如果你是说刷新页面也不变的话
那要把数据存到数据库里
如果没有数据库只能用cookie
但是cookie不能一直保存
第2个回答  2019-11-19
setInterval替换成settimeout即可,setInterval执行时为自动重复,而settimeout
则不会重复
相似回答