如何在clearinterval后恢复SetInterval?我的代码
$(document).ready(function() {
setTimeout(function(){
var ao =$('ul').hasClass('slides');
if(ao==true){
var detik = -1345;
var time = setInterval(function(){
detik+=0.5;
$('.slides').attr("style","width: "+oke+"px; transition-duration: 0s; transform: translate3d("+detik+"px, 0px, 0px);");
if (detik > 0 ){
detik = -1345;
}
}, 1);
$('.flex-prev, .flex-next').on('click',function(){
clearInterval(time);
});
}
},3000);
});
答案 0 :(得分:0)
您可以为setInterval()
制作一个功能。您可以调用startInterval()
函数重新启动计时器;
var detik = 0;
$(document).ready(function() {
setTimeout(function(){
var ao =$('ul').hasClass('slides');
if(ao==true){
detik = -1345;
startInterval();
$('.flex-prev, .flex-next').on('click',function(){
clearInterval(time);
});
}
},3000);
function startInterval(){
time = setInterval(function(){
detik+=0.5;
$('.slides').attr("style","width: "+oke+"px; transition-duration: 0s; transform: translate3d("+detik+"px, 0px, 0px);");
if (detik > 0 ){
detik = -1345;
}
}, 1);
}
});