微信小程序連續旋轉動畫this.animation.rotate


一、.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就行!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM