So I tried adding a slideshow with setTimeout, but after adding it other function stopped working. I tried changing setTimeout to setInterval, but also it didn't work.
Here is my code:
window.onload = function () {
setTimeout(function () {
let x = document.querySelector('.loaderWrap')
x.remove();
}, 1500)
}
let i = 0;
let images = [];
images[0] = ''
images[1] = ''
images[2] = ''
function changeImage() {
document.slide.src = images[i];
if(i<images.length - 1){
i++;
}else{
i=0;
}
setTimeout('changeImage()', 1000);
document.querySelector('.prev').onclick = function () {
if(i>0){
i--;
}
}
}window.onload = changeImage;
clearTimeout
is a function that takes a timeout id as a parameter. The timeout id is returned bysetTimeout
(whose overload taking a string is not recommended).window.onload =
you are overwriting the onload handler. UseaddEventListener('load', function() { .... })
to add event listeners non-destructively..loaderWrap
? Can you create a runnable snippet that reproduces the issues you have? (Use the toolbar)