基于mpvue利用wx.createAnimation()创建swiper动画
<template>
<div>
<swiper
v-if="imgUrls.length > 0"
:indidator-dots="imgUrls.length > 0"
autoplay
:circular="circular"
interval="10000"
@change="handleChange($event)"
><!--改变触发的方法-->
<block v-for="(item, index) in imgUrls" :key="index">
<swiper-item
class="wid100 dja"
:class="curIndex===index ? 'active_item' : 'item'"
:animation="index == curIndex ? animationData : animationData2"
><!--绑定动画类-->
<img :src="item.big_pic" style="width:100%;height:460rpx;" @click="topic(item.linkurl,item.adv_id)"/>
<!--banner图点击跳转-->
</swiper-item>
</block>
</swiper>
</div>
</template>
<script>
export default {
data() {
return { };
},
methods: {
handleChange(e) {
this.curIndex = e.mp.detail.current;
this.changeActive();
this.changeNormal();
},
// 收缩
changeNormal() {
var animation2 = wx.createAnimation({
duration: 500,
timingFunction: "ease"
});
this.animation2 = animation2;
animation2
.scale(0.9)
.opacity(0.3)
.step();
this.animationData2 = animation2.export();
},
// 展开
changeActive() {
var animation = wx.createAnimation({
duration: 500,
timingFunction: "ease"
});
this.animation = animation;
animation
.scale(1)
.opacity(1)
.step();
this.animationData = animation.export();
}
}
}
</script>