微信小程序——簡易動畫案例


wxml:

<view class="container">
<view animation="{{animation}}" class="view">我在做動畫</view>
</view>
<button type="primary" bindtap="translate">旋轉</button>

 

js:

//js
Page({
  data: {

  },
  onReady: function () {
    // 頁面渲染完成
    //實例化一個動畫
    this.animation = wx.createAnimation({
      // 動畫持續時間,單位ms,默認值 400
      duration: 400,
      /**
      * http://cubic-bezier.com/#0,0,.58,1 
      * linear 動畫一直較為均勻
      * ease 從勻速到加速在到勻速
      * ease-in 緩慢到勻速
      * ease-in-out 從緩慢到勻速再到緩慢
      * 
      * http://www.tuicool.com/articles/neqMVr
      * step-start 動畫一開始就跳到 100% 直到動畫持續時間結束 一閃而過
      * step-end 保持 0% 的樣式直到動畫持續時間結束 一閃而過
      */
      timingFunction: 'ease',
      // 延遲多長時間開始
      delay: 100,
      /**
      * 以什么為基點做動畫 效果自己演示
      * left,center right是水平方向取值,對應的百分值為left=0%;center=50%;right=100%
      * top center bottom是垂直方向的取值,其中top=0%;center=50%;bottom=100%
      */
      transformOrigin: 'left top 0',
      success: function (res) {
        console.log(res)
      }
    })
  },
  /**
  *位移
  */
  translate: function () {
    //x軸位移100px

    this.animation.translate(100, 0).step()
    this.setData({
      //輸出動畫
      animation: this.animation.export()
    })
  }


})

 


免責聲明!

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



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