swiper微场景开发流程:
1.下载最新的swiper,官方网址:http://www.swiper.com.cn/
2.API文档是配置项手册
中文教程---Swiper Animate是Swiper的动画效果,功能很强大
3.引入CSS和JS文件:
swiper.min.js和swiper.min.css。如果用到动画效果则需要引入swiper.animate.min.js和animate.min.css。以及适合移动端开发的rem.js(这个是自制的响应式布局js)
4.初始化
<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>
注意:下载最新的swiper(目前是4.1版本) ,一个页面使用多个swiper时,可以给每个容器加上ID或Class区分,要保留默认的类名swiper-container,注册对应的实例对象即可。默认的类名改动则会出现错误。
例:
<div class="swiper-container" id="swiper1">....<div>
<div class="swiper-container" id="swiper2">....<div>
<div class="swiper-container" id="swiper3">....<div>
JS
var swiper1 = new Swiper('#swiper1');
var swiper2 = new Swiper('#swiper2');
var swiper3 = new Swiper('#swiper3');
配置不的分页器也要给不同的分页器指定
ID或Class区分,修改默认类名失效。