Skip to content

Instantly share code, notes, and snippets.

@pbuzdin
Last active May 4, 2018 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbuzdin/65e9ca78c30c178af44124358a7b8036 to your computer and use it in GitHub Desktop.
Save pbuzdin/65e9ca78c30c178af44124358a7b8036 to your computer and use it in GitHub Desktop.
Swiper demo with custom pagination labels from data attributes
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>rockwool</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.2.6/css/swiper.min.css">
<style>
html, body {
height: 100%;
}
.swiper-container {
width: 100%;
height: 100%;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
display: flex;
justify-content: center;
align-items: center;
}
.swiper-pagination-bullet {
text-align: center;
opacity: 1;
border-radius: 0;
width: auto;
height: auto;
background: inherit;
}
.swiper-pagination-bullet-active {
color:#f00;
}
</style>
</head>
<body>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide" data-title="Slide 1">Slide 1</div>
<div class="swiper-slide" data-title="Slide 2">Slide 2</div>
<div class="swiper-slide" data-title="Slide 3">Slide 3</div>
</div>
<div class="swiper-pagination"></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.2.6/js/swiper.min.js"></script>
<script>
var titles = document.querySelectorAll('.swiper-container .swiper-slide');
var title = [];
titles.forEach(function(element) {
title.push(element.dataset.title);
});
var swiper = new Swiper('.swiper-container', {
pagination: {
el: '.swiper-pagination',
clickable: true,
renderBullet: function (index, className) {
return '<span class="' + className + '">' + title[index] + '</span>';
},
},
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment