最近有个需求需要将网站首页的 banner 弄成轮播效果的,同事推荐使用 swiper 来实现,记录一下。
swiper 官网地址:https://www.swiper.com.cn/
1、swiper 初始化
文章转载自:Swiper中文网 [https://www.swiper.com.cn]
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">slider1</div>
<div class="swiper-slide">slider2</div>
<div class="swiper-slide">slider3</div>
</div>
</div>
<script>
var mySwiper = new Swiper('.swiper-container', {
autoplay: true,//可选选项,自动滑动
})
</script>
我设置的参数:
initSwiper: function() {
var mySwiper = new Swiper('.swiper-container', {