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

252
Views
Mostrar el contenido de un div a la vez cada 4 segundos

Tengo un montón de divs de diapositivas dentro de un contenedor contenedor. Como puede ver, tengo dos de ellos configurados para mostrar: ninguno inicialmente. Cada 4000ms me gustaría hacer una transición suave a la siguiente diapositiva. He intentado algunas cosas con un intervalo establecido en js y sin suerte.

Aquí está mi código:

 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!