Created
March 26, 2026 10:35
-
-
Save Gaurav8757/41fa1bc4b84e2e496cf44055168f47fd to your computer and use it in GitHub Desktop.
Auto Carousel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Document</title> | |
| <style> | |
| .container .slide .item { | |
| width: 200px; | |
| height: 250px; | |
| position: absolute; | |
| top: 50%; | |
| transform: translate(0, -50%); | |
| box-shadow: 0 30px 50px #505050; | |
| background-position: 50% 50%; | |
| background-size: cover; | |
| display: inline-block; | |
| transition: all 0.5s; | |
| } | |
| .slide .item:nth-child(1), | |
| .slide .item:nth-child(2) { | |
| top: 0; | |
| left: 0; | |
| transform: translate(0, 0); | |
| width: 100%; | |
| height: 100%; | |
| transition: all .5s; | |
| } | |
| .slide .item:nth-child(3) { | |
| left: 50%; | |
| } | |
| .slide .item:nth-child(4) { | |
| left: calc(50% + 220px); | |
| } | |
| .slide .item:nth-child(5) { | |
| left: calc(50% + 440px); | |
| } | |
| .slide .item:nth-child(n + 6) { | |
| left: calc(50% + 660px); | |
| opacity: 0; | |
| } | |
| .item .content { | |
| position: absolute; | |
| top: 50%; | |
| left: 100px; | |
| width: 300px; | |
| text-align: left; | |
| color: #eee; | |
| transform: translate(0, -50%); | |
| font-family: system-ui; | |
| display: none; | |
| } | |
| .slide .item:nth-child(2) .content { | |
| display: block; | |
| } | |
| .content .name { | |
| font-size: 8rem; | |
| text-transform: uppercase; | |
| font-weight: bold; | |
| opacity: 0; | |
| animation: animate 1s ease-in-out 1 forwards; | |
| } | |
| .content .des { | |
| margin-top: 10px; | |
| margin-bottom: 20px; | |
| opacity: 0; | |
| animation: animate 1s ease-in-out 0.3s 1 forwards; | |
| } | |
| .content button { | |
| padding: 10px 20px; | |
| border: none; | |
| cursor: pointer; | |
| opacity: 0; | |
| border-radius: 10px; | |
| background-color: rgba(255, 255, 255, 0.673); | |
| transition: all 0.5s; | |
| animation: animate 1s ease-in-out 0.6s 1 forwards; | |
| } | |
| .content button:hover { | |
| background-color: rgb(255, 255, 255); | |
| } | |
| @keyframes animate { | |
| from { | |
| opacity: 0; | |
| transform: translate(0, 100px); | |
| filter: blur(33px); | |
| } | |
| to { | |
| opacity: 1; | |
| transform: translate(0); | |
| filter: blur(0); | |
| } | |
| } | |
| .button { | |
| display: none; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <div class="slide"> | |
| <div class="item" style=" | |
| background-image: url('https://images.unsplash.com/photo-1478760329108-5c3ed9d495a0?q=80&w=1074&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'); | |
| "> | |
| <div class="content"> | |
| <div class="name">Scotland</div> | |
| <div class="des"> | |
| Experience the mystical Highlands under twilight skies and misty lochs. | |
| </div> | |
| </div> | |
| </div> | |
| <div class="item" style=" | |
| background-image: url('https://images.unsplash.com/photo-1439792675105-701e6a4ab6f0?q=80&w=1173&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'); | |
| "> | |
| <div class="content"> | |
| <div class="name">Norway</div> | |
| <div class="des"> | |
| Chase the Northern Lights under star-lit skies along scenic fjord roads. | |
| </div> | |
| </div> | |
| </div> | |
| <div class="item" style=" | |
| background-image: url('https://images.unsplash.com/photo-1483982258113-b72862e6cff6?q=80&w=1170&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'); | |
| "> | |
| <div class="content"> | |
| <div class="name">New Zealand</div> | |
| <div class="des"> | |
| Wander dramatic, mist-laden mountain paths that feel straight out of a dream. | |
| </div> | |
| </div> | |
| </div> | |
| <div class="item" style=" | |
| background-image: url('https://images.unsplash.com/photo-1477346611705-65d1883cee1e?q=80&w=2070&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'); | |
| "> | |
| <div class="content"> | |
| <div class="name">Japan</div> | |
| <div class="des"> | |
| Discover serene mountain temples shrouded in dusk and ancient forest trails. | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| let slide = document.querySelector(".slide"); | |
| function moveNext() { | |
| let items = document.querySelectorAll(".item"); | |
| slide.appendChild(items[0]); | |
| } | |
| // Click any item to go to next | |
| slide.addEventListener("click", function () { | |
| moveNext(); | |
| resetTimer(); | |
| }); | |
| // Auto slide feature | |
| let slideTimer = setInterval(moveNext, 5000); | |
| function resetTimer() { | |
| clearInterval(slideTimer); | |
| slideTimer = setInterval(moveNext, 5000); | |
| } | |
| // Pause on hover | |
| const container = document.querySelector('.container'); | |
| container.addEventListener('mouseenter', () => clearInterval(slideTimer)); | |
| container.addEventListener('mouseleave', () => resetTimer()); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment