微信小程序> 微信小程序之实现动画循环播放怎么做步骤

微信小程序之实现动画循环播放怎么做步骤

浏览量:5591 时间: 来源:weixin_33881140

今天在做砍价页面的时候需要将一个按钮动起来,效果图如下:

小程序

 

其实它实现的原理很简单,就是循环的缩小放大。

css3中的animate 有个属性是 animation-iteration-count 可以控制动画的循环播放,但是小程序里面没有。该怎么实现呢?

无非就是2种状态的切换。

wxml:

<button class='cut-btn' open-type='share' animation="{{animationData}}">喊好友砍一刀</button>

 

js:

Page({  /**   * 页面的初始数据   */  data: {    animationData: {}  },    /**   * 生命周期函数--监听页面显示   */  onShow: function () {    var animation = wx.createAnimation({      duration: 500,      timingFunction: 'ease',    })    this.animation = animation    var next = true;    //连续动画关键步骤    setInterval(function () {      if (next) {        this.animation.scale(0.95).step()           next = !next;      } else {        this.animation.scale(1).step()        next = !next;      }      this.setData({        animationData: animation.export()      })    }.bind(this), 500)  },    /**   * 用户点击右上角分享   */  onShareAppMessage: function () {    }})

 

上述代码即可实现动画循环播放的效果了~~

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

最新资讯

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎