欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

微信小程序 连续旋转动画(this.animation.rotate)详解

程序员文章站 2022-03-21 15:31:30
微信小程序 连续旋转动画 一、.js中封装旋转动画方法   添加animation属性 data:{ animation:''" }...

微信小程序 连续旋转动画

一、.js中封装旋转动画方法

  添加animation属性

  data:{
    animation:''"
    }

  改变animation的值(官网提供角度范围是-180~180,但是我发现角度越大会一直旋转)

 onshow: function() {
    console.log('index---------onshow()')
     this.animation = wx.createanimation({
     duration: 1400,
     timingfunction: 'linear', // "linear","ease","ease-in","ease-in-out","ease-out","step-start","step-end"
     delay: 0,
     transformorigin: '50% 50% 0',
     success: function(res) {
      console.log("res")
     }
    })
   },
   rotateani: function (n) {
    console.log("rotate=="+n)
    this.animation.rotate(180*(n)).step()
    this.setdata({
     animation: this.animation.export()
    })
   },
 

二、在.wxml中需要的控件上添加animation属性

 <view class="show-iconview">
   <image src="{{src}}" class="show-iconimage" animation="{{animation}}" mode="scaletofill"></image>
 </view>

三、连续动画需要添加定时器

  this.interval = setinterval所传参数每次++i就行!

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!