這篇文章將為大家詳細(xì)講解有關(guān)animation如何實(shí)現(xiàn)讓云朵飄的動(dòng)畫實(shí)例,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、小程序設(shè)計(jì)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了輝南免費(fèi)建站歡迎大家使用!
創(chuàng)建一個(gè)動(dòng)畫實(shí)例animation。調(diào)用實(shí)例的方法來描述動(dòng)畫。最后通過動(dòng)畫實(shí)例的export方法導(dǎo)出動(dòng)畫數(shù)據(jù)傳遞給組件的animation屬性。
注意: export 方法每次調(diào)用后會(huì)清掉之前的動(dòng)畫操作
微信小程序提供了實(shí)現(xiàn)動(dòng)畫的api——animation,但卻不能循環(huán)播放,都是一次性的,動(dòng)完就Over了,下面提供一個(gè)用微信小程序的animation來實(shí)現(xiàn)循環(huán)動(dòng)畫的玩具,拋磚引玉,希望大家能想出更好的方法來實(shí)現(xiàn)真正的循環(huán)。說是玩具是因?yàn)檫@個(gè)循環(huán)動(dòng)畫通過js腳本的setInterval來實(shí)現(xiàn)的,但'setInterval'在實(shí)際運(yùn)行中會(huì)出現(xiàn)越來越嚴(yán)重的延遲,這是由于js的單線程運(yùn)行模式所決定的(具體可以搜本關(guān)資料看),所以動(dòng)畫間隙并不是那么流暢,所以先玩玩吧,讓我們來實(shí)現(xiàn)讓云朵飄……
截圖如下:

實(shí)現(xiàn)代碼:
index.wxml
<view class="clouds">
<image animation="{{animationCloudData}}" class="yun1" src="../../img/yun1.png"></image>
</view>index.js
onReady: function () {
// 頁面渲染完成
// 實(shí)例化一個(gè)動(dòng)畫
var that = this;
var i = 0
var ii = 0
var animationData = wx.createAnimation({
duration: 1000, // 默認(rèn)為400 動(dòng)畫持續(xù)時(shí)間,單位ms
timingFunction: 'ease-in-out',
//transformOrigin: '4px 91px'
});
var animationCloudData = wx.createAnimation({
duration: 1000, // 默認(rèn)為400 動(dòng)畫持續(xù)時(shí)間,單位ms
timingFunction: 'ease-in-out',
//transformOrigin: '4px 91px'
});
// 順序執(zhí)行,當(dāng)已經(jīng)執(zhí)行完上面的代碼就會(huì)開啟定時(shí)器
// 循環(huán)執(zhí)行代碼
//dotAnFun = setInterval(function () {});
/*setInterval(function () {
// 動(dòng)畫腳本定義
//animationData.rotate(6 * (++i)).step()
//animationData.scale(2, 2).rotate(45).step().scale(1, 1).step();
animationData.translateY(10).step({ duration: 500 }).translateY(-10).step({ duration: 500 });
// 更新數(shù)據(jù)
that.setData({
// 導(dǎo)出動(dòng)畫示例
animationData: animationData.export(),
//animationCloudData: animationCloudData.export(),
})
++i;
console.log(i);
}.bind(that), 2000);//循環(huán)時(shí)間 這里1000是1秒
*/
//動(dòng)畫的腳本定義必須每次都重新生成,不能放在循環(huán)外
animationCloudData.translateX(200).step({ duration: 5000 }).translateX(0).step({ duration: 5000 });
// 更新數(shù)據(jù)
that.setData({
// 導(dǎo)出動(dòng)畫示例
//animationData: animationData.export(),
animationCloudData: animationCloudData.export(),
})
setInterval(function () {
//動(dòng)畫的腳本定義必須每次都重新生成,不能放在循環(huán)外
animationCloudData.translateX(300).step({ duration: 5000 }).translateX(-100).step({ duration: 5000 });
// 更新數(shù)據(jù)
that.setData({
// 導(dǎo)出動(dòng)畫示例
//animationData: animationData.export(),
animationCloudData: animationCloudData.export(),
})
++ii;
console.log(ii);
}.bind(that),10000);//3000這里的設(shè)置如果小于動(dòng)畫step的持續(xù)時(shí)間的話會(huì)導(dǎo)致執(zhí)行一半后出錯(cuò)
}index.wxss
.clouds{
margin-top:320rpx;
}
.yun1{
width:320rpx;
height: 120rpx;
}關(guān)于“animation如何實(shí)現(xiàn)讓云朵飄的動(dòng)畫實(shí)例”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
本文題目:animation如何實(shí)現(xiàn)讓云朵飄的動(dòng)畫實(shí)例
網(wǎng)站地址:http://www.chinadenli.net/article28/ispecp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、ChatGPT、響應(yīng)式網(wǎng)站、商城網(wǎng)站、定制開發(fā)、微信公眾號(hào)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)