# SwiperDemo
**Repository Path**: wangshiq/swiper-demo
## Basic Information
- **Project Name**: SwiperDemo
- **Description**: Swiper插件学习、理解和deom
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2021-09-23
- **Last Updated**: 2021-09-24
## Categories & Tags
**Categories**: Uncategorized
**Tags**: Swiper
## README
# SwiperDemo
#### 介绍
Swiper插件学习、理解和demo
#### Swiper 基本结构
(导航等组件可以放在container之外)
类名swiper-container 是轮播插件结构的父级,一个窗口
类名swiper-wrapper 是所有轮播图的集合,默认情况为左右排序
类名swiper-slide 是每个轮播图元素
#### Swiper api
一.Autoplay(自动切换)
1.autoplay => 设置为true启动自动切换,并使用默认的切换设置,自动停留3s切换
autoplay:true, ==> 等同于
autoplay:{
delay:3000, //自动切换的时间间隔
stopOnLastSlide: false, //如果设置为true,当切换到最后一个slide时停止自动切换。(loop模式下无效)。
disableOnInteraction: true, //操作swiper之后,是否禁止autoplay;如果设置为false,用户操作swiper之后自动切换不会停止,每次都会重新启动autoplay。 操作包括触碰(touch),拖动,点击pagination等
}
2.delay =>
1)自动切换的时间间隔,以ms为单位;
2)可以为某个slide单独添加停留时间,;
3.stopOnLastSlide =>
1)如果设置为true,当切换到最后一个slide时停止自动切换;当处于loop模式下无效;
2)若stopOnLastSlid:false;loop:false;且slidec为最后一张时,会由3-2-1,退回第一个slide,重新开始轮播;
4.disableOnInteraction =>
操作Swiper后(包括触碰、拖动、点击等),是否禁止autoplay(自动切换);
5.reverseDirection =>
开启反向自动轮播;1——3——2——1——3
6.waitForTransition =>
waitForTransition:{
speed:2500,
autoplay:{
delay:1500,
waitForTransition:true,
},
}
waitForTransition:false, => 不会等待过渡结束在开始下一轮,在第一张和最后一张时会呈现 "还未执行完毕,就开始下一轮的状态";
7.pauseOnMouseEnter =>
pauseOnMouseEnter:true,鼠标置于swiper时暂停自动切换,鼠标离开时恢复自动切换,若开启了disableOnInteraction,那么自动切换不会恢复;
//6.6.2之前的版本需要通过代码实现此功能
mySwiper.el.onmouseover = function(){
mySwiper.autoplay.stop();
}
mySwiper.el.onmouseout = function(){
mySwiper.autoplay.start();
}
8.mySwiper.autoplay.running => 若swiper 开启了autoplay,此值为true;
9.mySwiper.autoplay.start() =>
$('#btn1').click(function(){
mySwiper.autoplay.stop();
})
$('#btn2').click(function(){
mySwiper.autoplay.start();
})
开启/关闭 autoplay;
二.parallax(视察效果)
1.视差位移变化 =>
data-swiper-parallax 接受两种参数,1)number(px);2) percentage(百分百);通过正负号控制进出方向
2.视差透明度变化 =>
data-swiper-parallax-opacity
3.视差缩放变化 =>
data-swiper-parallax-scale
三.effect(切换效果)
var mySwiper = new swiper(".mySwiper-container"{
effect : 'fade',// 淡入 => 修改 slide 样式实现轮播淡入效果
effect : 'cube',//方块
effect : 'coverflow',//3d流
slidesPerView: 3, //同一屏幕容纳的数量
centeredSlides: true,
effect : 'flip',//3d翻转
})