Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!