Answer the question
In order to leave comments, you need to log in
How to delay the execution of setInterval?
var slider = document.querySelectorAll("article");
var circleone = document.getElementById("circle-one");
var circletwo = document.getElementById("circle-two");
var interval = setInterval(function() {
for(var i = 0; i < slider.length; i++){
var item = parseInt(slider[i].style.left);
if(item === 0){
item = 100;
slider[i].style.transitionDuration = "0s";
slider[i].style.left = item + "%";
}else{
item-=100;
slider[i].style.transitionDuration = "0.5s";
slider[i].style.left = item + "%";
}
}
}, 4000);
circleone.onclick = function(){
slider[0].style.left = 0 + "%";
slider[1].style.left = 100 + "%";
}
Answer the question
In order to leave comments, you need to log in
if I understood correctly, then you need a reboot type for the interval.
maybe like this
var slider = document.querySelectorAll("article");
var circleone = document.getElementById("circle-one");
var circletwo = document.getElementById("circle-two");
var interval;
function Run(){
clearInterval(interval);
interval = setInterval(function() {
for(var i = 0; i < slider.length; i++){
var item = parseInt(slider[i].style.left);
if(item === 0){
item = 100;
slider[i].style.transitionDuration = "0s";
slider[i].style.left = item + "%";
}else{
item-=100;
slider[i].style.transitionDuration = "0.5s";
slider[i].style.left = item + "%";
}
}
}, 4000);
}
Run();
circleone.onclick = function(){
slider[0].style.left = 0 + "%";
slider[1].style.left = 100 + "%";
Run();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question