| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <!DOCTYPE html>
- <html lang="es">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Carrusel de Cards</title>
- <style>
- * {
- box-sizing: border-box;
- margin: 0;
- padding: 0;
- }
- body {
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100vh;
- background-color: #f4f4f4;
- }
- .carousel-container {
- display: flex;
- flex-direction: column;
- align-items: center;
- position: relative;
- }
- .carousel {
- display: flex;
- transition: transform 0.4s ease-in-out;
- overflow: hidden;
- width: 300px;
- height: 200px;
- }
- .carousel-track {
- display: flex;
- transition: transform 0.4s ease-in-out;
- }
- .card {
- min-width: 100%;
- height: 100%;
- background-color: #fff;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 24px;
- border: 1px solid #ddd;
- border-radius: 10px;
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
- }
- .carousel-controls {
- display: flex;
- justify-content: space-between;
- width: 120px;
- margin-top: 15px;
- }
- .carousel-btn {
- background-color: #333;
- color: #fff;
- border: none;
- padding: 10px;
- cursor: pointer;
- border-radius: 50%;
- }
- </style>
- </head>
- <body>
- <div class="carousel-container">
- <div class="carousel">
- <div class="carousel-track">
- <div class="card">Card 1</div>
- <div class="card">Card 2</div>
- <div class="card">Card 3</div>
- <div class="card">Card 4</div>
- <div class="card">Card 5</div>
- </div>
- </div>
- <!-- Contenedor de botones centrados -->
- <div class="carousel-controls">
- <button id="prevBtn" class="carousel-btn">⟨</button>
- <button id="nextBtn" class="carousel-btn">⟩</button>
- </div>
- </div>
- <script>
- const carouselTrack = document.querySelector('.carousel-track');
- const cards = document.querySelectorAll('.card');
- const prevBtn = document.getElementById('prevBtn');
- const nextBtn = document.getElementById('nextBtn');
- let currentIndex = 0;
- const totalCards = cards.length;
- function showCard(index) {
- carouselTrack.style.transform = `translateX(${-index * 100}%)`;
- }
- prevBtn.addEventListener('click', () => {
- currentIndex = (currentIndex > 0) ? currentIndex - 1 : totalCards - 1;
- showCard(currentIndex);
- });
- nextBtn.addEventListener('click', () => {
- currentIndex = (currentIndex < totalCards - 1) ? currentIndex + 1 : 0;
- showCard(currentIndex);
- });
- setInterval(() => {
- currentIndex = (currentIndex < totalCards - 1) ? currentIndex + 1 : 0;
- showCard(currentIndex);
- }, 3000);
- </script>
- </body>
- </html>
|