Skip to content

Instantly share code, notes, and snippets.

@kaiimran
Last active September 1, 2021 06:10
Show Gist options
  • Save kaiimran/30fc6a160265415d8aeb60d80582d2ee to your computer and use it in GitHub Desktop.
Save kaiimran/30fc6a160265415d8aeb60d80582d2ee to your computer and use it in GitHub Desktop.
Swiper.js - Infinite loop slides, lazy load images, autoplay, clickable pagination, no left/right arrow.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Swiper demo</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"
/>
<!-- Link Swiper's CSS -->
<link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css" />
<!-- Demo styles -->
<style>
html,
body {
position: relative;
height: 100%;
}
body {
background: #eee;
color: #000;
margin: 0;
padding: 0;
}
.swiper {
max-width: 990px;
width: 100%;
height: 40%;
--swiper-navigation-color: #fff !important;
--swiper-pagination-color: #fff !important;
border-radius: 5px;
box-shadow: 0px 4px 20px 2px rgba(0,0,0,0.4);
-webkit-box-shadow: 0px 4px 20px 2px rgba(0,0,0,0.4);
-moz-box-shadow: 0px 4px 20px 2px rgba(0,0,0,0.4);
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #000;
}
.swiper-slide img {
width: auto;
height: 100%;
max-width: 100%;
max-height: 100%;
border-radius: 5px;
-ms-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
position: absolute;
left: 50%;
top: 50%;
}
</style>
</head>
<body>
<!-- Swiper -->
<div
class="swiper mySwiper"
>
<div class="swiper-wrapper">
<div class="swiper-slide">
<!-- Required swiper-lazy class and image source specified in data-src attribute -->
<img
data-src="https://swiperjs.com/demos/images/nature-1.jpg"
class="swiper-lazy"
/>
<!-- Preloader image -->
<div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div>
</div>
<div class="swiper-slide">
<img
data-src="https://swiperjs.com/demos/images/nature-2.jpg"
class="swiper-lazy"
/>
<div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div>
</div>
<div class="swiper-slide">
<img
data-src="/img/shop1.png"
class="swiper-lazy"
/>
<div class="swiper-lazy-preloader swiper-lazy-preloader-white"></div>
</div>
</div>
<div class="swiper-pagination"></div>
</div>
<!-- Swiper JS -->
<script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>
<!-- Initialize Swiper -->
<script>
var swiper = new Swiper(".mySwiper", {
lazy: true,
pagination: {
el: ".swiper-pagination",
clickable: true,
},
autoplay: {
delay: 5000,
},
loop: true,
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment