新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OS動畫
動畫分為靜態(tài)動畫和連續(xù)動畫。

靜態(tài)動畫
靜態(tài)動畫的核心是 transform 樣式,主要可以實現(xiàn)以下三種變換類型,一次樣式設(shè)置只能實現(xiàn)一種類型變換。
- translate:沿水平或垂直方向?qū)⒅付ńM件移動所需距離。
- scale:橫向或縱向?qū)⒅付ńM件縮小或放大到所需比例。
- rotate:將指定組件沿橫軸或縱軸或中心點旋轉(zhuǎn)指定的角度。
靜態(tài)動畫只有開始狀態(tài)和結(jié)束狀態(tài),沒有中間狀態(tài),如果需要設(shè)置中間的過渡狀態(tài)和轉(zhuǎn)換效果,需要使用連續(xù)動畫實現(xiàn)。具體的使用示例如下,更多信息請參考組件。
hello
hello
hello
/* xxx.css */
.container {
flex-direction: column;
align-items: center;
}
.translate {
height: 300px;
width: 400px;
font-size: 100px;
background-color: #008000;
transform: translate(300px);
}
.rotate {
height: 300px;
width: 400px;
font-size: 100px;
background-color: #008000;
transform-origin: 200px 100px;
transform: rotateX(45deg);
}
.scale {
height: 300px;
width: 400px;
font-size: 100px;
background-color: #008000;
transform: scaleX(1.5);
}
圖1 靜態(tài)動畫效果圖
連續(xù)動畫
連續(xù)動畫的核心是 animation 樣式,它定義了動畫的開始狀態(tài)、結(jié)束狀態(tài)以及時間和速度的變化曲線。通過 animation 樣式可以實現(xiàn)的效果有:
- animation-name:設(shè)置動畫執(zhí)行后應(yīng)用到組件上的背景顏色、透明度、寬高和變換類型。
- animation-delay 和 animation-duration:分別設(shè)置動畫執(zhí)行后元素延遲和持續(xù)的時間。
- animation-timing-function:描述動畫執(zhí)行的速度曲線,使動畫更加平滑。
- animation-iteration-count:定義動畫播放的次數(shù)。
- animation-fill-mode:指定動畫執(zhí)行結(jié)束后是否恢復(fù)初始狀態(tài)。
animation 樣式需要在 css 文件中先定義 keyframe,在 keyframe 中設(shè)置動畫的過渡效果,并通過一個樣式類型在 hml 文件中調(diào)用。animation-name 的使用示例如下:
animation-name
color
opacity
/* xxx.css */
.item-container {
margin-bottom: 50px;
margin-right: 60px;
margin-left: 60px;
flex-direction: column;
align-items: flex-start;
}
.group {
margin-bottom: 150px;
flex-direction: column;
align-items: flex-start;
}
.header {
margin-bottom: 20px;
}
.item {
background-color: #f76160;
}
.txt {
text-align: center;
width: 200px;
height: 100px;
}
.button {
width: 200px;
font-size: 30px;
color: #ffffff;
background-color: #09ba07;
}
.color {
animation-name: Color;
animation-duration: 8000ms;
}
.opacity {
animation-name: Opacity;
animation-duration: 8000ms;
}
@keyframes Color {
from {
background-color: #f76160;
}
to {
background-color: #09ba07;
}
}
@keyframes Opacity {
from {
opacity: 0.9;
}
to {
opacity: 0.1;
}
}
// xxx.js
export default {
data: {
colorParam: '',
opacityParam: '',
},
showAnimation: function () {
this.colorParam = '';
this.opacityParam = '';
this.colorParam = 'color';
this.opacityParam = 'opacity';
},
}
圖2 連續(xù)動畫效果圖
文章標題:創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OS動畫
本文路徑:http://www.dlmjj.cn/article/cdhsgge.html


咨詢
建站咨詢
