0
Hello, I’m having a problem in my slide, it starts with the blank browser window and after the 5 sec starts to appear the images, and when it arrives in the last image it would have to return the first.
I’ve searched a lot of places, but every time I fix one thing, it ruins another.
I know I have to play an activation class in the first picture, but as I am informing the images by Js, I’m not getting.
the HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Slide Show</title>
<link rel="stylesheet" href="css/slider.css">
</head>
<body>
<div class="banner-topo">
<img name="slide">
</div>
<a class="prev" onClick="prevImg()">❮</a>
<a class="next" onClick="nextImg()">❯</a>
<br/>
</body>
<script src="js/slider.js"></script>
</body>
</html>
o Js:
var i = -1;
var images =
['/img/home/banner/_perfiladeira_de_perfis_estruturais_esquadros.jpg',
'/img/home/banner/_perfiladeira_de_telhas_metalicas_esquadros.jpg',
'/img/home/banner/_maquina_de_corte_longitudinal_slitter_esquadros.jpg',
'/img/home/banner/_maquina_de_corte_longitudinal_e_transversal_combinado_esquadros.jpg',
'/img/home/banner/_linha_de_producao_esquadros.jpg',
'/img/home/banner/_software_profil_esquadros.jpg'];
function nextImg(){
document.slide.src = images[(++i)%3];
if (i>=images.length) return true;
}
function prevImg(){
document.slide.src = images[(i = i<=0 ? 0 : i-1)%3];
}
window.onload = () => {
let time = 4000;
let id_interval = setInterval(() => {
if(nextImg()) {
clearInterval(id_interval);
}
}, time);
}'
Because vc does not initialize before entering setInterval, the image at position 0: ;
... window.onload = () => {
 let time = 4000; document.slide.src = images[0] ...
– Ivan Ferrer
It worked, thank you very much.
– Renan Ranzani