基于swiper及基本轮播效果
- 自动轮播+无缝轮播
- 左右按钮控制效果
- 指示器(分页器)
代码示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>swiper轮播</title>
<!-- 引入swiper css 及 js 文件 -->
<!-- <link rel="stylesheet" href="Swiper-3.4.2/dist/css/swiper.min.css" />
<script src="Swiper-3.4.2/dist/js/swiper.min.js"></script> -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.4.2/css/swiper.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.4.2/js/swiper.min.js"></script>
<!-- 设置轮播最外层大小 -->
<style type="text/css">
.swiper-container {
width: 1200px;
height: 400px;
}
</style>
</head>
<body>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide"><a href=""><img src="images/1.jpg"/></a></div>
<div class="swiper-slide"><img src="images/2.jpg" /></div>
<div class="swiper-slide"><img src="images/3.jpg" /></div>
<div class="swiper-slide"><img src="images/4.jpg" /></div>
<div class="swiper-slide"><img src="images/5.jpg" /></div>
</div>
<!-- 如果需要分页器 -->
<div class="swiper-pagination"></div>
<!-- 如果需要导航按钮 -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<!-- 如果需要滚动条 -->
<div class="swiper-scrollbar"></div>
</div>
<script type="text/javascript">
// 调用swiper效果,并进行配置
var mySwiper = new Swiper('.swiper-container', {
/*常用配置:开启轮播、无缝轮播、左右按钮控制、分液器指示、分页器控制、操作后再次自动轮播*/
//自动轮播
autoplay:500,
//无缝轮播
loop:true,
// 如果需要前进后退按钮
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
// 如果需要分页器
pagination: '.swiper-pagination',
//用户操作以后 依旧可以自动轮播
disableOnInteraction:false,
//分页器可以点击切换图片
paginationClickable:true
})
</script>
</body>
</html>
来源:CSDN
作者:sun_chen_93
链接:https://blog.csdn.net/sun_chen_93/article/details/103242569