微信小程序 連續旋轉動畫
一、.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就行!
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答