我正在 Javascript 上构建一个自定义滑块,我希望每次用户单击滑块的 div 时,滑块应该停止 X 秒。
我的代码是:
$(document).ready(function () {
var ciclo;
var index_slide = 1;
function startSlidercicle() {
ciclo = setInterval( function() {
// Slider code goes here
}, 3000);
}
//Here I start the slider animation
startSlidercicle();
//When the user clicks on a div called 'slide', stop the cycle and start again the animation cycle
$('.slide').on('click', function() {
clearInterval(ciclo);
setTimeout(startSlidercicle(), 3000);
});
});
但问题是每次单击并停止滑块时,循环开始的速度越来越快。我该如何解决?