Slide Scale 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"> <title>Slide & Scale Carousel</title> <style> body { font-family: 'Arial', sans-serif; background: #fafafa; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } .carousel-container { position: relative; width: 90%; max-width: 1000px; overflow: hidden; border-radius: 15px; box-shadow: 0 15px 30px rgba(0,0,0,0.2); } .carousel-slide { display: flex; transition: transform 0.5s ease-in-out; } .carousel-item { min-width: 100%; height: 500px; display: flex; justify-content: center; align-items: center; font-size: 2rem; color: white; position: relative; overflow: hidden; } .carousel-item img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.5s ease-in-out; } .carousel-item:hover img { transform: scale(1.05); } .carousel-item:nth-child(1) { background: linear-gradient(135deg, #6a11cb, #2575fc); } .carousel-item:nth-child(2) { background: linear-gradient(135deg, #ff7e5f, #feb47b); } .carousel-item:nth-child(3) { background: linear-gradient(135deg, #43cea2, #185a9d); } .carousel-item:nth-child(4) { background: linear-gradient(135deg, #ff9966, #ff5e62); } .carousel-icons { position: absolute; bottom: 15px; left: 50%; transform: translateX(-50%); display: flex; } .carousel-icon { width: 15px; height: 15px; margin: 0 5px; background: white; border-radius: 50%; cursor: pointer; transition: background 0.3s; } .carousel-icon.active { background: #333; } .carousel-controls { position: absolute; top: 50%; width: 100%; display: flex; justify-content: space-between; transform: translateY(-50%); } .carousel-control { background: rgba(0,0,0,0.5); border: none; color: white; padding: 10px; cursor: pointer; font-size: 1.5rem; transition: background 0.3s; } .carousel-control:hover { background: rgba(0,0,0,0.8); } </style> </head> <body> <div class="carousel-container"> <div class="carousel-slide"> <div class="carousel-item"> <img src="pics/p1.png" alt="Slide & Scale 1"> </div> <div class="carousel-item"> <img src="pics/p2.png" alt="Slide & Scale 2"> </div> <div class="carousel-item"> <img src="pics/p3.png" alt="Slide & Scale 3"> </div> <div class="carousel-item"> <img src="pics/p4.png" alt="Slide & Scale 4"> </div> </div> <div class="carousel-icons"> <div class="carousel-icon active"></div> <div class="carousel-icon"></div> <div class="carousel-icon"></div> <div class="carousel-icon"></div> </div> <div class="carousel-controls"> <button type="button" class="carousel-control" id="prevBtn">❮</button> <button type="button" class="carousel-control" id="nextBtn">❯</button> </div> </div> <script> const slide = document.querySelector('.carousel-slide'); const items = document.querySelectorAll('.carousel-item'); const prevBtn = document.getElementById('prevBtn'); const nextBtn = document.getElementById('nextBtn'); const icons = document.querySelectorAll('.carousel-icon'); let counter = 0; const updateCarousel = () => { slide.style.transform = 'translateX(' + (-100 * counter) + '%)'; icons.forEach((icon, index) => { icon.classList.toggle('active', index === counter); }); }; nextBtn.addEventListener('click', () => { counter = (counter + 1) % items.length; updateCarousel(); }); prevBtn.addEventListener('click', () => { counter = (counter - 1 + items.length) % items.length; updateCarousel(); }); icons.forEach((icon, index) => { icon.addEventListener('click', () => { counter = index; updateCarousel(); }); }); updateCarousel(); </script> </body> </html>