(1) 本节知识点
- 使用分页器: pagination
- 分页器样式: paginationType
- 分页器可点: paginationClickable
- 显示隐藏分页器: paginationHide
- 指定分页器标签类型: paginationElement
- 分页器渲染
- paginationBulletRender
- paginationFractionRender
- paginationProgressRender
(2) 代码实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<link rel="stylesheet" href="css/swiper.min.css" />
<script src="js/swiper.min.js"></script>
</head>
<style>
* {
margin: 0px;
padding: 0px;
}
.swiper-container {
width: 800px;
height: 300px;
border: 10px solid #ccc;
}
.swiper-slide {
font-size: 50px;
}
.swiper-slide:nth-of-type(1) {
background: yellow;
}
.swiper-slide:nth-of-type(2) {
background: blue;
}
.swiper-slide:nth-of-type(3) {
background: red;
}
.swiper-pagination-bullet {
width: 45px;
height: 45px;
}
</style>
<body>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">Slide 1</div>
<div class="swiper-slide">Slide 2</div>
<div class="swiper-slide">Slide 3</div>
</div>
<div class="swiper-pagination"></div>
</div>
</body>
<script>
window.onload = function () {
var mySwiper = new Swiper('.swiper-container', {
direction: 'horizontal',
pagination: '.swiper-pagination',
paginationType: 'bullets',
paginationClickable: true,
paginationElement: 'i',
paginationBulletRender: function (swiper, index, classname) {
return (
"<span class='" +
classname +
"'style='color:#fff;line-height:45px;'>" +
index +
'</span>'
)
},
})
}
</script>
</html>