W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
動(dòng)畫(huà)分為靜態(tài)動(dòng)畫(huà)和連續(xù)動(dòng)畫(huà)。
靜態(tài)動(dòng)畫(huà)的核心是 transform 樣式,主要可以實(shí)現(xiàn)以下三種變換類(lèi)型,一次樣式設(shè)置只能實(shí)現(xiàn)一種類(lèi)型變換。
靜態(tài)動(dòng)畫(huà)只有開(kāi)始狀態(tài)和結(jié)束狀態(tài),沒(méi)有中間狀態(tài),如果需要設(shè)置中間的過(guò)渡狀態(tài)和轉(zhuǎn)換效果,需要使用連續(xù)動(dòng)畫(huà)實(shí)現(xiàn)。具體的使用示例如下,更多信息請(qǐng)參考組件。
<!-- xxx.hml -->
<div class="container">
<text class="translate">hello</text>
<text class="rotate">hello</text>
<text class="scale">hello</text>
</div>
/* 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)動(dòng)畫(huà)效果圖
連續(xù)動(dòng)畫(huà)的核心是 animation 樣式,它定義了動(dòng)畫(huà)的開(kāi)始狀態(tài)、結(jié)束狀態(tài)以及時(shí)間和速度的變化曲線。通過(guò) animation 樣式可以實(shí)現(xiàn)的效果有:
animation 樣式需要在 css 文件中先定義 keyframe,在 keyframe 中設(shè)置動(dòng)畫(huà)的過(guò)渡效果,并通過(guò)一個(gè)樣式類(lèi)型在 hml 文件中調(diào)用。animation-name 的使用示例如下:
<!-- xxx.hml -->
<div class="item-container">
<div class="group">
<text class="header">animation-name</text>
<div class="item {{colorParam}}">
<text class="txt">color</text>
</div>
<div class="item {{opacityParam}}">
<text class="txt">opacity</text>
</div>
<input class="button" type="button" name="" value="show" onclick="showAnimation"/>
</div>
</div>
/* 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ù)動(dòng)畫(huà)效果圖
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: