Line_Baslat();
setInterval(function(){ moveLeft(); Line_Baslat(); },4000);
function Line_Tekrar () {
$("#dv_line").animate({width:"0%"},0);
};
function Line_Baslat () {
$("#dv_line").animate({width:"100%"},4000);
};
function refseh () {
setInterval(update,4000);
};
$("#prev").click(function(){
moveLeft();
refresh();
});
$("#next").click(function(){
moveRight();
refresh();
});
答案 0 :(得分:0)
setInterval
函数返回该间隔的ID,您可以使用它来取消它。例如在你的情况下
Line_Baslat();
var timeout;
function refresh () {
if (timeout) {
clearInterval(timeout);
}
timeout = setInterval(function(){ moveLeft(); Line_Baslat(); },4000);
};
function Line_Tekrar () {
$("#dv_line").animate({width:"0%"},0);
};
function Line_Baslat () {
$("#dv_line").animate({width:"100%"},4000);
};
$("#prev").click(function(){
moveLeft();
refresh();
});
$("#next").click(function(){
moveRight();
refresh();
});
答案 1 :(得分:0)
尝试将setInterval
正文存储在另一个函数中,如下所示:
//doStuff variables.
var a = 0;
function doStuff(){
//interval body
}
var interval;
interval = setInterval(function(){
doStuff(); //Call Interval Body
},timeout);
clearInterval(interval); //clear interval
//reset interval to call body function
interval = setInterval(function(){
doStuff(); //Call Interval Body
},timeout);
这允许您重新启动/重置间隔。