1、先鏈接css和js文件
<link rel="stylesheet" type="text/css" href="css/swiper-3.3.1.min.css"/>
<link rel="stylesheet" type="text/css" href="css/animate.min.css"/>
<script type="text/javascript" src="js/swiper-3.3.1.min.js"></script>
<script type="text/javascript" src="js/swiper.animate1.0.2.min.js"></script>
2、初始化
/* 初始化swiper.js */
var mySwiper = new Swiper(‘.swiper-container‘,{
pagination : ‘.swiper-pagination‘, //分頁器
direction:‘vertical‘, //垂直方向換頁
slideToClickedSlide: true, //slide1向slide2 swipe的過程中輕點slide1會回到slide1
/* 初始化animate */
onInit: function(swiper){ //Swiper2.x的初始化是onFirstInit
swiperAnimateCache(swiper); //隱藏動畫元素
setTimeout(function(){ //2s后開始運行動畫(移動端總是沒加載完圖片就開始動畫了。。。。。)
swiperAnimate(swiper); //初始化完成開始動畫
},2000)
},
onSlideChangeEnd: function(swiper){
swiperAnimate(swiper); //每個slide切換結束時也運行當前slide動畫
}
})
4、使用animate的動畫,注意class中要加“ani”
<img class="ani pic" src="pic.jpg" swiper-animate-effect="zoomIn" swiper-animate-duration="0.7s" />
自定義的動畫效果:
html中添加class=“ani” 和swiper-animate-effect=“動畫名”,可以與animate自帶的動畫一樣,在每次切換時運行動畫。
<img class="ani pic" src="pic.jpg" swiper-animate-effect="shutter2" />
css中定義效果
@-webkit-keyframes shutter2{
from{top: 100%;}
to{top: 0;}
}
.shutter2{
-webkit-animation: shutter2 0.5s forwards;
animation: shutter2 0.5s forwards;
}
API地址:https://www.swiper.com.cn/usage/animate/
官網最下方可以看動畫效果
方法二:
動畫只引用 animate.min.css
樣式里面要加
.swiper-slide-active .animate {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
.swiper-slide-active .m-bounceInLeft {
-webkit-animation-name: bounceInLeft;
animation-name: bounceInLeft;
}
<div class="animate m-bounceInLeft"></div>
重新命一下名避免跟animate.min.css里面的樣式沖突,但是可直接引用里面的動畫
