A Pen by Dustyn Altimus on CodePen.
Created
May 2, 2022 11:02
-
-
Save vtuz/24ad15f9b381a09ade0796ce8ff00436 to your computer and use it in GitHub Desktop.
Swiper Auto Centered - Fixed Height
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
<body> | |
<!-- Slider main container --> | |
<div class="swiper-container my-gallery"> | |
<!-- Additional required wrapper --> | |
<div class="swiper-wrapper"> | |
<!-- Slides --> | |
<div class="swiper-slide"> | |
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject" class=""> | |
<a href="https://cdn.pixabay.com/photo/2019/08/19/07/45/pets-4415649_960_720.jpg" itemprop="contentUrl" data-size="2136x1424"> | |
<img src='https://cdn.pixabay.com/photo/2019/08/19/07/45/pets-4415649_960_720.jpg' class="slide-image"/> | |
</a> | |
</figure> | |
</div> | |
<div class="swiper-slide"> | |
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject" class=""> | |
<a href="https://cdn.pixabay.com/photo/2019/07/02/08/10/sunny-4311828_960_720.jpg" itemprop="contentUrl" data-size="2136x1424"> | |
<img src='https://cdn.pixabay.com/photo/2019/07/02/08/10/sunny-4311828_960_720.jpg' class="slide-image"/> | |
</a> | |
</figure> | |
</div> | |
<div class="swiper-slide"> | |
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject" class=""> | |
<a href="https://cdn.pixabay.com/photo/2019/08/25/16/57/purple-4429887_960_720.jpg" itemprop="contentUrl" data-size="2136x1424"> | |
<img src='https://cdn.pixabay.com/photo/2019/08/25/16/57/purple-4429887_960_720.jpg' class="slide-image"/> | |
</a> | |
</figure> | |
</div> | |
<div class="swiper-slide"> | |
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject" class=""> | |
<a href="https://cdn.pixabay.com/photo/2019/02/15/11/04/book-3998252_960_720.jpg" itemprop="contentUrl" data-size="2136x1424"> | |
<img src='https://cdn.pixabay.com/photo/2019/02/15/11/04/book-3998252_960_720.jpg' class="slide-image"/> | |
</a> | |
</figure> | |
</div> | |
<div class="swiper-slide"> | |
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject" class=""> | |
<a href="https://cdn.pixabay.com/photo/2019/08/24/18/12/parasol-4428078_960_720.jpg" itemprop="contentUrl" data-size="2136x1424"> | |
<img src='https://cdn.pixabay.com/photo/2019/08/24/18/12/parasol-4428078_960_720.jpg' class="slide-image"/> | |
</a> | |
</figure> | |
</div> | |
<div class="swiper-slide"> | |
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject" class=""> | |
<a href="https://cdn.pixabay.com/photo/2019/08/25/13/36/grapes-4429520_960_720.jpg" itemprop="contentUrl" data-size="2136x1424"> | |
<img src='https://cdn.pixabay.com/photo/2019/08/25/13/36/grapes-4429520_960_720.jpg' class="slide-image"/> | |
</a> | |
</figure> | |
</div> | |
<div class="swiper-slide"> | |
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject" class=""> | |
<a href="https://cdn.pixabay.com/photo/2019/08/28/12/58/nature-4436704_960_720.jpg" itemprop="contentUrl" data-size="2136x1424"> | |
<img src='https://cdn.pixabay.com/photo/2019/08/28/12/58/nature-4436704_960_720.jpg' class="slide-image"/> | |
</a> | |
</figure> | |
</div> | |
<div class="swiper-slide"> | |
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject" class=""> | |
<a href="https://cdn.pixabay.com/photo/2019/08/24/13/36/banteng-4427640_960_720.jpg" itemprop="contentUrl" data-size="2136x1424"> | |
<img src='https://cdn.pixabay.com/photo/2019/08/24/13/36/banteng-4427640_960_720.jpg' class="slide-image"/> | |
</a> | |
</figure> | |
</div> | |
</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
//Swiper Initialization | |
$(document).ready(function () { | |
//initialize swiper when document ready | |
var mySwiper = new Swiper ('.swiper-container', { | |
// Optional parameters | |
loop: true, | |
loopedSlides: 8, | |
centeredSlides: true, | |
slidesPerView: 'auto', | |
spaceBetween: 4, | |
}) | |
}); |
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://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.0/js/swiper.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.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
.swiper-container{ | |
width: 100%; | |
} | |
.swiper-wrapper { | |
width: 50%; | |
} | |
.swiper-slide { | |
text-align: center; | |
width: auto; | |
} | |
.slide-image { | |
height: 400px; | |
width: auto; | |
} | |
.my-gallery figure { | |
margin: 0px; | |
} |
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://cdnjs.cloudflare.com/ajax/libs/Swiper/4.5.0/css/swiper.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment