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

255
Vistas
Show one div's contents at a time every 4 seconds

I have a bunch of slide divs inside of a wrapper container. As you can see I have two of them set to display: none initially. Every 4000ms I would like to smoothly transition into the next slide. I have tried a few things with set interval in js and no luck.

Here is my code:

body {
  padding: 0;
  margin: 0;
}

.wrapper {}

.slide {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  height: 100vh;
}

img {
  outline: solid 5px #fff;
}

.single img {
  width: 100%;
  height: 100%;
}

.split img {
  width: 50%;
  height: 100%;
}

.quad img {
  width: 50%;
  height: 50%;
}
<div class="wrapper">
  <div class="slide single">
    <img src="https://dummyimage.com/3840x2160/000/fff">
  </div>

  <div class="slide split" style="display: none;">
    <img src="https://dummyimage.com/3840x2160/000/fff">
    <img src="https://dummyimage.com/3840x2160/000/fff">
  </div>

  <div class="slide quad" style="display: none;">
    <img src="https://dummyimage.com/3840x2160/000/fff">
    <img src="https://dummyimage.com/3840x2160/000/fff">
    <img src="https://dummyimage.com/3840x2160/000/fff">
    <img src="https://dummyimage.com/3840x2160/000/fff">
  </div>
</div>

almost 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <link rel="stylesheet" href="styles.css">
 <script src="script.js"></script>
 <title>Mostrar Divs</title>
</head>
<body>
 <div class="container">
 <div class="box" id="box1">Contenido 1</div>
 <div class="box" id="box2">Contenido 2</div>
 <div class="box" id="box3">Contenido 3</div>
 <div class="box" id="box4">Contenido 4</div>
 </div>
</body>
</html>

CSS:

 .box {
 display: none; /* Ocultar todos los elementos .box inicialmente */
 padding: 20px;
 border: 1px solid #ccc;
 margin-bottom: 10px;
 display: none;
}
.visible {
 display: block;
}

javascript:

 document.addEventListener("DOMContentLoaded", function () {
 const boxes = document.querySelectorAll(".box");
 let currentIndex = 0;

 function showBox(index) {
 boxes.forEach((box) => {
 box.style.display = "none";
 });

 boxes[index].style.display = "block";
 }

 function rotateBox() {
 showBox(currentIndex);
 currentIndex = (currentIndex + 1) % boxes.length;
 }

 showBox(currentIndex)
 setInterval(rotateBox(), 4000); // Cambiar cada 4 segundos (4000 milisegundos)
});
almost 4 years ago · Santiago Trujillo 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