顯式動畫
參考文檔:
https://gitee.com/openharmony/docs/blob/5654c2b940ab3e2f4f0baf435e630c4ef3536428/zh-cn/application-dev/reference/arkui-ts/ts-explicit-animation.md
來看一個簡單的示例:
@Entry
@Component
structAnimationPage{
//位移屬性
@State_translate:TranslateOptions={
x:0,
y:0,
z:0
}
build(){
Flex({
alignItems:ItemAlign.Center,
justifyContent:FlexAlign.Center,
direction:FlexDirection.Column
}){
Button('執(zhí)行動畫').margin({bottom:50}).onClick(()=>{
//添加一個簡單顯式動畫
animateTo({
duration:1000,//動畫時長
tempo:0.5,//播放速率
curve:Curve.EaseInOut,//動畫曲線
delay:0,//動畫延遲
iterations:1,//播放次數(shù)
playMode:PlayMode.Normal,//動畫模式
},()=>{
//閉包內(nèi)更改狀態(tài)
this._translate={
x:0,
y:100,
z:0
}
})
})
Column(){
Text('Animate.css')
.fontSize(50)
.fontWeight(FontWeight.Bold)
.fontColor('#351c75')
.translate(this._translate)//位移變換
}
}
.width('100%')
.height('100%')
}
}

如果我們希望向下位移完成后,再向右位移,就需要在第一個動畫完成后再進行第二個動畫,即在第一個動畫的 onFinish 函數(shù)中執(zhí)行第二個動畫。

這樣組合起來可以構(gòu)成一個更復(fù)雜的連續(xù)動畫:
//單步動畫執(zhí)行函數(shù)
animationStep(value:AnimateParam,event:()=>void){
return()=>{
returnnewPromise((resolve)=>{
letonFinish=value.onFinish
value.onFinish=()=>{
if(onFinish)onFinish()
resolve(true)
}
animateTo(value,event)
})
}
}
創(chuàng)建 4 步動畫:
aboutToAppear(){
//每步動畫執(zhí)行時長
lettime=200
this.step1=this.animationStep({
duration:time,//動畫時長
tempo:0.5,//播放速率
curve:Curve.EaseInOut,//動畫曲線
delay:0,//動畫延遲
iterations:1,//播放次數(shù)
playMode:PlayMode.Normal,//動畫模式
onFinish:()=>{
//動畫執(zhí)行完成
console.info('playend')
}
},()=>{
//閉包內(nèi)更改狀態(tài)
this._translate={
x:0,
y:100,
z:0
}
})
this.step2=this.animationStep({
duration:time,//動畫時長
tempo:0.5,//播放速率
curve:Curve.EaseInOut,//動畫曲線
delay:0,//動畫延遲
iterations:1,//播放次數(shù)
playMode:PlayMode.Normal,//動畫模式
onFinish:()=>{
//動畫執(zhí)行完成
console.info('playend')
}
},()=>{
//閉包內(nèi)更改狀態(tài)
this._translate={
x:100,
y:100,
z:0
}
})
this.step3=this.animationStep({
duration:time,//動畫時長
tempo:0.5,//播放速率
curve:Curve.EaseInOut,//動畫曲線
delay:0,//動畫延遲
iterations:1,//播放次數(shù)
playMode:PlayMode.Normal,//動畫模式
onFinish:()=>{
//動畫執(zhí)行完成
console.info('playend')
}
},()=>{
//閉包內(nèi)更改狀態(tài)
this._translate={
x:100,
y:0,
z:0
}
})
this.step4=this.animationStep({
duration:time,//動畫時長
tempo:0.5,//播放速率
curve:Curve.EaseInOut,//動畫曲線
delay:0,//動畫延遲
iterations:1,//播放次數(shù)
playMode:PlayMode.Normal,//動畫模式
onFinish:()=>{
//動畫執(zhí)行完成
console.info('playend')
}
},()=>{
//閉包內(nèi)更改狀態(tài)
this._translate={
x:0,
y:0,
z:0
}
})
}
順序執(zhí)行 4 步動畫:
Button('執(zhí)行動畫').margin({bottom:50}).onClick(async()=>{
awaitthis.step1()
awaitthis.step2()
awaitthis.step3()
awaitthis.step4()
})
實現(xiàn) AnimateCSS 動畫
AnimateCSS:
https://cdn.bootcdn.net/ajax/libs/animate.css/4.1.1/animate.css
https://animate.style/
pulse 動畫:
看下 pulse 動畫樣式代碼:
.animate__pulse{
-webkit-animation-name:pulse;
animation-name:pulse;
-webkit-animation-timing-function:ease-in-out;
animation-timing-function:ease-in-out;
}
@keyframespulse{
from{
-webkit-transform:scale3d(1,1,1);
transform:scale3d(1,1,1);
}
50%{
-webkit-transform:scale3d(1.05,1.05,1.05);
transform:scale3d(1.05,1.05,1.05);
}
to{
-webkit-transform:scale3d(1,1,1);
transform:scale3d(1,1,1);
}
}
ETS 實現(xiàn):
@State_scale:ScaleOptions={
x:1,
y:1,
z:1
}
...
Column(){
Text('Animate.css')
.fontSize(50)
.fontWeight(FontWeight.Bold)
.fontColor('#351c75')
.translate(this._translate)//位移變換
.scale(this._scale)//比例變化
}
動畫方法:
-
傳遞一個動畫總時長 time
-
第一步動畫執(zhí)行段為 0%-50%,所以動畫執(zhí)行時長為總時長time * 50%
- 第二步動畫執(zhí)行段為 50%-100%,所以動畫執(zhí)行時長為總時長time * 50%
asyncpulse(time){
//0%-50%
letstep1=this.animationStep({
duration:time*0.5,//動畫時長
tempo:0.5,//播放速率
curve:Curve.EaseInOut,//動畫曲線
delay:0,//動畫延遲
iterations:1,//播放次數(shù)
playMode:PlayMode.Normal,//動畫模式
},()=>{
this._scale={
x:1.05,
y:1.05,
z:1.05
}
})
//50%-100%
letstep2=this.animationStep({
duration:time*0.5,//動畫時長
tempo:0.5,//播放速率
curve:Curve.EaseInOut,//動畫曲線
delay:0,//動畫延遲
iterations:1,//播放次數(shù)
playMode:PlayMode.Normal,//動畫模式
},()=>{
this._scale={
x:1,
y:1,
z:1
}
})
awaitstep1()
awaitstep2()
}
執(zhí)行動畫:
Button('執(zhí)行PULSE動畫').margin({bottom:50}).onClick(async()=>{
this.pulse(500)
})

審核編輯 :李倩
聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。
舉報投訴
-
函數(shù)
+關(guān)注
關(guān)注
3文章
4413瀏覽量
67210 -
Harmony
+關(guān)注
關(guān)注
0文章
108瀏覽量
3527
原文標題:在鴻蒙上實現(xiàn)AnimateCSS動畫
文章出處:【微信號:gh_834c4b3d87fe,微信公眾號:OpenHarmony技術(shù)社區(qū)】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
相關(guān)推薦
熱點推薦
SGTools--動畫控件--屏幕實現(xiàn)動畫顯示 就是這么簡單
詳細步驟可以觀看視頻,
實現(xiàn)動畫很簡單,提前準備好gif文件和一個張背景圖
使用SGTools工具,就可以制作動畫界面啦
視頻中屏幕型號是7寸 HMT070ATA-9C
發(fā)表于 09-16 10:29
分享---儲能UI界面能量流動動畫實現(xiàn)方法
本文分享 工商業(yè)儲能設(shè)備的UI界面中如何實現(xiàn) 能量流動的動畫效果。
本例子效果 基于拓普微工業(yè)級 7寸屏電容串口屏(HMT070ETA-D型號)實現(xiàn):
第1步:建立工程和頁面
使用SGTools新建
發(fā)表于 09-02 18:22
【EASY EAI Orin Nano開發(fā)板試用體驗】使用和LVGL的anim(簡易動畫)和animimg(圖像動畫)控件組合實現(xiàn)復(fù)雜的動畫功能
在LVGL中,實現(xiàn)復(fù)雜的動畫功能往往需要anim和animimg兩個控件組合實現(xiàn)的,對于anim控件來說,可以實現(xiàn)對obj多邊形的平移,縮放
發(fā)表于 08-09 21:37
【EASY EAI Orin Nano開發(fā)板試用體驗】使用Linux posix文件讀取接口和LVGL的animimg(圖像動畫)控件實現(xiàn)動畫播放以及
)
甚至還可以在lv_animimg控件上添加互動控件比如button,實現(xiàn)動態(tài)背景效果:(置底視頻)
lv_animimg實現(xiàn)沒有任何問題,然后就是LVGL定時器
發(fā)表于 07-22 00:34
harmony-utils之CrashUtil,異常相關(guān)工具類
harmony-utils之CrashUtil,異常相關(guān)工具類
harmony-utils之DeviceUtil,設(shè)備相關(guān)工具類
harmony-utils之DeviceUtil,設(shè)備相關(guān)工具類
harmony-utils之DisplayUtil,屏幕相關(guān)工具類
harmony-utils之DisplayUtil,屏幕相關(guān)工具類
harmony-utils之EmitterUtil,Emitter工具類
harmony-utils之EmitterUtil,Emitter工具類
harmony-utils之FileUtil,文件相關(guān)工具類
harmony-utils之FileUtil,文件相關(guān)工具類
harmony-utils之ImageUtil,圖片相關(guān)工具類
harmony-utils之ImageUtil,圖片相關(guān)工具類
用DeepSeek-R1實現(xiàn)自動生成Manim動畫
? 作者:算力魔方創(chuàng)始人/英特爾創(chuàng)新大使劉力 前面我們分享了在本地運行能與OpenAI-o1 能力相媲美的DeepSeek-R1 模型。本文將介紹如何使用DeepSeek-R1實現(xiàn)自動生成Manim
在Harmony上實現(xiàn)AnimateCSS動畫
評論