Vibrant Carousel - MeggiTools
Run
Toggle Theme
Share Link
<!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="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"> <title>Vibrant Carousel</title> <style> body { margin: 0; font-family: Arial, sans-serif; background: linear-gradient(to right, #ff6f61, #de1d6d); overflow: hidden; background-attachment: fixed; } .carousel { position: relative; width: 80%; max-width: 1000px; margin: 50px auto; border-radius: 20px; overflow: hidden; } .carousel .slides { display: flex; transition: transform 0.5s ease-in-out; } .carousel .slide { min-width: 100%; box-sizing: border-box; } .carousel .slide img { width: 100%; border-radius: 20px; } .carousel .navigation { position: absolute; top: 50%; width: 100%; display: flex; justify-content: space-between; transform: translateY(-50%); } .carousel .nav-button { background: rgba(255, 255, 255, 0.5); border: none; padding: 12px; border-radius: 5px; cursor: pointer; color: #ffffff; transition: background 0.3s ease; } .carousel .nav-button:hover { background: rgba(255, 255, 255, 0.8); } .carousel .nav-prev { left: 20px; } .carousel .nav-next { right: 20px; } .carousel .nav-button i { font-size: 2rem; } @import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css'); </style> </head> <body> <div class="carousel"> <div class="slides"> <div class="slide"> <img src="https://via.placeholder.com/1000x500/ff6f61/ffffff?text=Slide+1" alt="Slide 1"> </div> <div class="slide"> <img src="https://via.placeholder.com/1000x500/de1d6d/ffffff?text=Slide+2" alt="Slide 2"> </div> <div class="slide"> <img src="https://via.placeholder.com/1000x500/ff6f61/ffffff?text=Slide+3" alt="Slide 3"> </div> </div> <div class="navigation"> <button class="nav-button nav-prev"><i class="fas fa-chevron-left"></i></button> <button class="nav-button nav-next"><i class="fas fa-chevron-right"></i></button> </div> </div> <script> const prevButton = document.querySelector('.nav-prev'); const nextButton = document.querySelector('.nav-next'); const slides = document.querySelector('.slides'); const slideCount = document.querySelectorAll('.slide').length; let index = 0; function showSlide(i) { if (i >= slideCount) index = 0; else if (i < 0) index = slideCount - 1; else index = i; slides.style.transform = `translateX(-${index * 100}%)`; } prevButton.addEventListener('click', () => showSlide(index - 1)); nextButton.addEventListener('click', () => showSlide(index + 1)); setInterval(() => showSlide(index + 1), 4000); </script> </body> </html>