A Pen by Naga Vinod Kumar on CodePen.
Created
December 25, 2020 15:59
-
-
Save nagavinodcse/e8f4da1efed0132ad8998b885e8c79e0 to your computer and use it in GitHub Desktop.
AlpineJS Carousel using Swiper + Tailwindcss
This file contains 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
<div x-data="{swiper: null}" | |
x-init="swiper = new Swiper($refs.container, { | |
loop: true, | |
slidesPerView: 1, | |
spaceBetween: 0, | |
breakpoints: { | |
640: { | |
slidesPerView: 1, | |
spaceBetween: 0, | |
}, | |
768: { | |
slidesPerView: 2, | |
spaceBetween: 0, | |
}, | |
1024: { | |
slidesPerView: 3, | |
spaceBetween: 0, | |
}, | |
}, | |
})" | |
class="relative w-10/12 mx-auto flex flex-row" | |
> | |
<div class="absolute inset-y-0 left-0 z-10 flex items-center"> | |
<button @click="swiper.slidePrev()" | |
class="bg-white -ml-2 lg:-ml-4 flex justify-center items-center w-10 h-10 rounded-full shadow focus:outline-none"> | |
<svg viewBox="0 0 20 20" fill="currentColor" class="chevron-left w-6 h-6"><path fill-rule="evenodd" d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z" clip-rule="evenodd"></path></svg> | |
</button> | |
</div> | |
<div class="swiper-container" x-ref="container"> | |
<div class="swiper-wrapper"> | |
<!-- Slides --> | |
<div class="swiper-slide p-4"> | |
<div class="flex flex-col rounded shadow overflow-hidden"> | |
<div class="flex-shrink-0"> | |
<img class="h-48 w-full object-cover" src="https://images.unsplash.com/photo-1496128858413-b36217c2ce36?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1679&q=80" alt=""> | |
</div> | |
</div> | |
</div> | |
<div class="swiper-slide p-4"> | |
<div class="flex flex-col rounded shadow overflow-hidden"> | |
<div class="flex-shrink-0"> | |
<img class="h-48 w-full object-cover" src="https://images.unsplash.com/photo-1598951092651-653c21f5d0b9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=80" alt=""> | |
</div> | |
</div> | |
</div> | |
<div class="swiper-slide p-4"> | |
<div class="flex flex-col rounded shadow overflow-hidden"> | |
<div class="flex-shrink-0"> | |
<img class="h-48 w-full object-cover" src="https://images.unsplash.com/photo-1598946423291-ce029c687a42?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=80" alt=""> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<div class="absolute inset-y-0 right-0 z-10 flex items-center"> | |
<button @click="swiper.slideNext()" | |
class="bg-white -mr-2 lg:-mr-4 flex justify-center items-center w-10 h-10 rounded-full shadow focus:outline-none"> | |
<svg viewBox="0 0 20 20" fill="currentColor" class="chevron-right w-6 h-6"><path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd"></path></svg> | |
</button> | |
</div> | |
</div> |
This file contains 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
<script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script> | |
<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js"></script> |
This file contains 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
<link href="https://unpkg.com/swiper/swiper-bundle.min.css" rel="stylesheet" /> | |
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/1.7.3/tailwind.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment