動(dòng)畫(huà)水還是比較深的,這里只是簡(jiǎn)單介紹下小程序中動(dòng)畫(huà)的一些屬性和注意事項(xiàng),做動(dòng)畫(huà)前一定要整理好思路將動(dòng)畫(huà)一步步分解,再進(jìn)行組合!這里只做引入。
wx.createAnimation(object)
看官方介紹
1.創(chuàng)建一個(gè)動(dòng)畫(huà)實(shí)例animation。調(diào)用實(shí)例的方法來(lái)描述動(dòng)畫(huà)。最后通過(guò)動(dòng)畫(huà)實(shí)例的export方法導(dǎo)出動(dòng)畫(huà)數(shù)據(jù)傳遞給組件的animation屬性。
2.調(diào)用動(dòng)畫(huà)操作方法后要調(diào)用 step() 來(lái)表示一組動(dòng)畫(huà)完成,可以在一組動(dòng)畫(huà)中調(diào)用任意多個(gè)動(dòng)畫(huà)方法,一組動(dòng)畫(huà)中的所有動(dòng)畫(huà)會(huì)同時(shí)開(kāi)始,一組動(dòng)畫(huà)完成后才會(huì)進(jìn)行下一組動(dòng)畫(huà)。step 可以傳入一個(gè)跟 wx.createAnimation() 一樣的配置參數(shù)用于指定當(dāng)前組動(dòng)畫(huà)的屬性
這還是比較好理解的比如第一條對(duì)應(yīng)代碼animation: this.animation.export()
第二條比如縮放動(dòng)畫(huà),也就說(shuō)是一組scale,scaleX, scaleY…為一縮放動(dòng)畫(huà)組的一個(gè)動(dòng)畫(huà)方法,縮放動(dòng)畫(huà)組和旋轉(zhuǎn)動(dòng)畫(huà)組通過(guò)step()鏈接,按順序執(zhí)行。代碼中體驗(yàn)吧!看效果反過(guò)來(lái)看會(huì)更容易理解
主要屬性:

這里主要樹(shù)下timingFunction和transformOrigin
timingFunction 設(shè)置動(dòng)畫(huà)效果
transformOrigin 設(shè)置動(dòng)畫(huà)的基點(diǎn) 默認(rèn)%50 %50 0
left,center right是水平方向取值,對(duì)應(yīng)的百分值為left=0%;center=50%;right=100%
top center bottom是垂直方向的取值,其中top=0%;center=50%;bottom=100%
動(dòng)畫(huà)組及動(dòng)畫(huà)方法
樣式:

旋轉(zhuǎn):

縮放:

偏移:

傾斜:

矩陣變形:

演示單個(gè)動(dòng)畫(huà)組效果

wxml
<view class="container"> <view animation="{{animation}}" class="view">我在做動(dòng)畫(huà)</view></view><button type="primary" bindtap="rotate">旋轉(zhuǎn)</button>js
Page({ data:{ text:"Page animation", animation: '' }, onLoad:function(options){ // 頁(yè)面初始化 options為頁(yè)面跳轉(zhuǎn)所帶來(lái)的參數(shù) }, onReady:function(){ // 頁(yè)面渲染完成 //實(shí)例化一個(gè)動(dòng)畫(huà) this.animation = wx.createAnimation({ // 動(dòng)畫(huà)持續(xù)時(shí)間,單位ms,默認(rèn)值 400 duration: 1000, /** * http://cubic-bezier.com/#0,0,.58,1 * linear 動(dòng)畫(huà)一直較為均勻 * ease 從勻速到加速在到勻速 * ease-in 緩慢到勻速 * ease-in-out 從緩慢到勻速再到緩慢 * * http://www.tuicool.com/articles/neqMVr * step-start 動(dòng)畫(huà)一開(kāi)始就跳到 100% 直到動(dòng)畫(huà)持續(xù)時(shí)間結(jié)束 一閃而過(guò) * step-end 保持 0% 的樣式直到動(dòng)畫(huà)持續(xù)時(shí)間結(jié)束 一閃而過(guò) */ timingFunction: 'linear', // 延遲多長(zhǎng)時(shí)間開(kāi)始 delay: 100, /** * 以什么為基點(diǎn)做動(dòng)畫(huà) 效果自己演示 * left,center right是水平方向取值,對(duì)應(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({ //輸出動(dòng)畫(huà) animation: this.animation.export() }) }, onShow:function(){ // 頁(yè)面顯示 }, onHide:function(){ // 頁(yè)面隱藏 }, onUnload:function(){ // 頁(yè)面關(guān)閉 }})演示多個(gè)動(dòng)畫(huà)組效果

這里我們只需要更改以下代碼即可
/**
* 旋轉(zhuǎn)
*/
rotate: function() {
//兩個(gè)動(dòng)畫(huà)組 一定要以step()結(jié)尾
/**
* 動(dòng)畫(huà)順序 順時(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({
//輸出動(dòng)畫(huà)
animation: this.animation.export()
})
}
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注