Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
Trying to make a simple slideshow with setinterval() in Js

No onClick, just automatic change of image and caption every second. Here's the code I have so far: HTML:

<div class="col-md-6">
                <h2>Fishing Slide Show</h2>
                <h4 id="caption">Casting on the Upper Kings</h4>
                <img id="slide" src="images/casting1.jpg" alt="" height="200px">
                <div id="slides">
                    <img src="images/casting1.jpg" alt="Casting on the Upper Kings" height="200px">
                    <img src="images/casting2.jpg" alt="Casting on the Lower Kings" height="200px">
                    <img src="images/catchrelease.jpg" alt="Catch and Release on the Big Horn" height="200px">
                    <img src="images/fish.jpg" alt="Catching on the South Fork" height="200px">
                    <img src="images/lures.jpg" alt="The Lures for Catching" height="200px">
                </div>
            </div>

And this is my Javascript:

 var img_array = ["images/casting1.jpg", "images/casting2.jpg"
                    ,"images/catchrelease.jpg", "images/fish.jpg" 
                    ,"images/lures.jpg"];
   var alt_array = ["Casting on the Upper Kings", "Casting on the Lower Kings", 
                     "Catch and Release on the Big Horn", "Catching on the South Fork", 
                     "The Lures for Catching"];

   var currImg = 0;
   var currAlt = 0;

   function slideShow();{
 
         img.src = img_array[index++, img_array.length];       
         img.alt = alt_array[index++, alt_array.length];

       //document.getElementById("slides").src = img_array[currImg];
       //document.getElementById("slides").alt = alt_array[currAlt];
}
   let stop = setInterval(slideShow, 1000);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Here's a simple slideshow I made.

You simply have the first slide have the active tab, then you use .nextElementSibling to get the next slide.

function runSlideshow() {
  const current = document.querySelector(".slide.current");
  current.classList.toggle("current");
  current.nextElementSibling ?
    current.nextElementSibling.classList.toggle("current") :
    clearInterval(slideshow);
}

const slideshow = setInterval(runSlideshow, 2000);
.slide {
  height: 200px;
  display: none;
}

.slide.current {
  display: block;
}
<div id="container">
  <img class="slide current" src="https://cataas.com/cat/6136c137ebad510011b54b90" />
  <img class="slide" src="https://cataas.com/cat/6136be59ebad510011b54b88" />
  <img class="slide" src="https://cataas.com/cat/61307aa542fcca001bb841f5" />
  <img class="slide" src="https://cataas.com/cat/6123cb0fe8503700118bdb62" />
  <img class="slide" src="https://cataas.com/cat/6120c8103a342d0013920e23" />
</div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda