利用wx.createAnimation()创建swiper动画

本文介绍如何使用MPVue结合wx.createAnimation()方法创建轮播图动画效果。通过监听swiper组件的改变事件实现图片切换时的动画效果,包括图片的缩放和平滑过渡。此外还介绍了如何为当前显示的图片应用不同的动画样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

基于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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值