動畫水還是比較深的,這里只是簡單介紹下小程序中動畫的一些屬性和注意事項(xiàng),做動畫前一定要整理好思路將動畫一步步分解,再進(jìn)行組合!這里只做引入。愛掏網(wǎng) - it200.com
wx.createAnimation(object)
-
看官方介紹
1.創(chuàng)建一個(gè)動畫實(shí)例animation。愛掏網(wǎng) - it200.com調(diào)用實(shí)例的方法來描述動畫。愛掏網(wǎng) - it200.com最后通過動畫實(shí)例的export方法導(dǎo)出動畫數(shù)據(jù)傳遞給組件的animation屬性。愛掏網(wǎng) - it200.com
2.調(diào)用動畫操作方法后要調(diào)用 step() 來表示一組動畫完成,可以在一組動畫中調(diào)用任意多個(gè)動畫方法,一組動畫中的所有動畫會同時(shí)開始,一組動畫完成后才會進(jìn)行下一組動畫。愛掏網(wǎng) - it200.comstep 可以傳入一個(gè)跟 wx.createAnimation() 一樣的配置參數(shù)用于指定當(dāng)前組動畫的屬性
這還是比較好理解的比如第一條對應(yīng)代碼animation: this.animation.export()
第二條比如縮放動畫,也就說是一組scale,scaleX, scaleY…為一縮放動畫組的一個(gè)動畫方法,縮放動畫組和旋轉(zhuǎn)動畫組通過step()鏈接,按順序執(zhí)行。愛掏網(wǎng) - it200.com代碼中體驗(yàn)吧!看效果反過來看會更容易理解
主要屬性:
這里主要樹下timingFunction和transformOrigin
-
timingFunction 設(shè)置動畫效果
- linear 默認(rèn)為linear 動畫一直較為均勻
- ease 開始時(shí)緩慢中間加速到快結(jié)束時(shí)減速
- ease-in 開始的時(shí)候緩慢
- ease-in-out 開始和結(jié)束時(shí)減速
- ease-out 結(jié)束時(shí)減速
- step-start 動畫一開始就跳到 100% 直到動畫持續(xù)時(shí)間結(jié)束 一閃而過
- step-end 保持 0% 的樣式直到動畫持續(xù)時(shí)間結(jié)束 一閃而過
-
transformOrigin 設(shè)置動畫的基點(diǎn) 默認(rèn)%50 %50 0
- left,center right是水平方向取值,對應(yīng)的百分值為left=0%;center=50%;right=100%
- top center bottom是垂直方向的取值,其中top=0%;center=50%;bottom=100%
動畫組及動畫方法
樣式:
旋轉(zhuǎn):
縮放:
偏移:
傾斜:
矩陣變形:
演示單個(gè)動畫組效果
wxml
view class="container">view animation="{{animation}}" class="view">我在做動畫view>
view>
button type="primary" bindtap="rotate">旋轉(zhuǎn)button>
js
Page({data:{text:"Page animation",animation: ''},onLoad:function(options){// 頁面初始化 options為頁面跳轉(zhuǎn)所帶來的參數(shù)},onReady:function(){// 頁面渲染完成//實(shí)例化一個(gè)動畫this.animation = wx.createAnimation({// 動畫持續(xù)時(shí)間,單位ms,默認(rèn)值 400duration: 1000, /*** http://cubic-bezier.com/#0,0,.58,1 * linear 動畫一直較為均勻* ease 從勻速到加速在到勻速* ease-in 緩慢到勻速* ease-in-out 從緩慢到勻速再到緩慢* * http://www.tuicool.com/articles/neqMVr* step-start 動畫一開始就跳到 100% 直到動畫持續(xù)時(shí)間結(jié)束 一閃而過* step-end 保持 0% 的樣式直到動畫持續(xù)時(shí)間結(jié)束 一閃而過*/timingFunction: 'linear',// 延遲多長時(shí)間開始delay: 100,/*** 以什么為基點(diǎn)做動畫 效果自己演示* left,center right是水平方向取值,對應(yīng)的百分值為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)}})},/*** 旋轉(zhuǎn)*/rotate: function() {//順時(shí)針旋轉(zhuǎn)10度//this.animation.rotate(150).step()this.setData({//輸出動畫animation: this.animation.export()})},onShow:function(){// 頁面顯示},onHide:function(){// 頁面隱藏},onUnload:function(){// 頁面關(guān)閉}
})
演示多個(gè)動畫組效果
這里我們只需要更改以下代碼即可
/*** 旋轉(zhuǎn)*/rotate: function() {//兩個(gè)動畫組 一定要以step()結(jié)尾/*** 動畫順序 順時(shí)針旋轉(zhuǎn)150度>x,y 放大二倍>x,y平移10px>x,y順時(shí)針傾斜>改變樣式和設(shè)置寬度寬度*/this.animation.rotate(150).step().scale(2).step().translate(10).step().skew(10).step().opacity(0.5).width(10).step({ducation: 8000})this.setData({//輸出動畫animation: this.animation.export()})}