Elegant Flow Carousel Slider - 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"> <title>Elegant Flow Carousel Slider</title> <style> body { margin: 0; font-family: 'Arial', sans-serif; background-color: #e0f7fa; display: flex; justify-content: center; align-items: center; height: 100vh; } .carousel { position: relative; width: 70%; max-width: 900px; overflow: hidden; border-radius: 20px; box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2); background-color: #ffffff; } .carousel-track { display: flex; transition: transform 0.7s ease-in-out; } .carousel-slide { min-width: 100%; box-sizing: border-box; } .carousel-slide img { width: 100%; border-radius: 20px; } .carousel-slide-content { position: absolute; bottom: 5%; left: 5%; color: #fff; font-size: 1.4em; background: rgba(0, 0, 0, 0.6); padding: 15px; border-radius: 10px; } .carousel-slide-content h2 { margin: 0; } .carousel-buttons { position: absolute; top: 50%; width: 100%; display: flex; justify-content: space-between; transform: translateY(-50%); } .carousel-button { background: rgba(0, 0, 0, 0.5); border: none; font-size: 2.5em; cursor: pointer; color: #fff; border-radius: 50%; width: 50px; height: 50px; display: flex; justify-content: center; align-items: center; } .carousel-indicators { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; justify-content: center; } .carousel-indicator { width: 12px; height: 12px; border-radius: 50%; background: #000; margin: 0 6px; cursor: pointer; transition: background 0.3s; } .carousel-indicator.active { background: #00acc1; } @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } .carousel-slide { animation: fadeIn 0.7s ease-in-out; } </style> </head> <body> <div class="carousel"> <div class="carousel-track"> <div class="carousel-slide"> <img src="https://via.placeholder.com/900x500/ff7f7f/333333?text=Slide+1" alt="Slide 1"> </div> <div class="carousel-slide"> <img src="https://via.placeholder.com/900x500/7f7fff/333333?text=Slide+2" alt="Slide 2"> </div> <div class="carousel-slide"> <img src="https://via.placeholder.com/900x500/7fff7f/333333?text=Slide+3" alt="Slide 3"> </div> </div> <div class="carousel-buttons"> <button class="carousel-button" id="prevBtn">❮</button> <button class="carousel-button" id="nextBtn">❯</button> </div> <div class="carousel-indicators"> <div class="carousel-indicator active" data-slide="0"></div> <div class="carousel-indicator" data-slide="1"></div> <div class="carousel-indicator" data-slide="2"></div> </div> </div> <script> const track = document.querySelector('.carousel-track'); const slides = Array.from(track.children); const nextButton = document.getElementById('nextBtn'); const prevButton = document.getElementById('prevBtn'); const indicators = Array.from(document.querySelectorAll('.carousel-indicator')); let currentSlide = 0; const updateIndicators = (index) => { indicators.forEach(indicator => indicator.classList.remove('active')); indicators[index].classList.add('active'); }; const moveToSlide = (track, currentSlide, targetSlide) => { track.style.transform = 'translateX(-' + targetSlide.style.left + ')'; }; const setSlidePosition = (slide, index) => { slide.style.left = 100 * index + '%'; }; slides.forEach(setSlidePosition); nextButton.addEventListener('click', () => { const currentSlideElement = slides[currentSlide]; currentSlide = (currentSlide + 1) % slides.length; const nextSlideElement = slides[currentSlide]; moveToSlide(track, currentSlideElement, nextSlideElement); updateIndicators(currentSlide); }); prevButton.addEventListener('click', () => { const currentSlideElement = slides[currentSlide]; currentSlide = (currentSlide - 1 + slides.length) % slides.length; const prevSlideElement = slides[currentSlide]; moveToSlide(track, currentSlideElement, prevSlideElement); updateIndicators(currentSlide); }); indicators.forEach(indicator => { indicator.addEventListener('click', () => { const targetIndex = parseInt(indicator.getAttribute('data-slide')); if (targetIndex !== currentSlide) { const currentSlideElement = slides[currentSlide]; const targetSlideElement = slides[targetIndex]; currentSlide = targetIndex; moveToSlide(track, currentSlideElement, targetSlideElement); updateIndicators(currentSlide); } }); }); </script> </body> </html>