2017年前端火了,微信小程序、weex、reactnative,就連支付寶也搞起了小程序,總感覺這是原生要?dú)绲墓?jié)奏啊,我也乘熱上車萬一波。
animation 屬性是一個(gè)簡(jiǎn)寫屬性,用于設(shè)置六個(gè)動(dòng)畫屬性:
值 描述
animation-name 規(guī)定需要綁定到選擇器的 keyframe 名稱。。
animation-duration 規(guī)定完成動(dòng)畫所花費(fèi)的時(shí)間,以秒或毫秒計(jì)。
animation-timing-function 規(guī)定動(dòng)畫的速度曲線。
animation-delay 規(guī)定在動(dòng)畫開始之前的延遲。
animation-iteration-count 規(guī)定動(dòng)畫應(yīng)該播放的次數(shù)。
animation-direction 規(guī)定是否應(yīng)該輪流反向播放動(dòng)畫。
方法特別多,本文主要用2個(gè)。
translate3d(1,1,0)
你可以理解為(左右,上下,大?。┳兓?。
rotate3d(1,1,0,45deg)
1.兩朵云除了大小和初始位置不通,其他都相同。
.cloud {
position: absolute;
z-index: 3;
width:99px;height:64px; top: 0;
right: 0;
bottom: 0;
animation: cloud 5s linear infinite;
}
@keyframes cloud {
from {
transform: translate3d(-125rpx, 0, 0);
}
to {
transform: translate3d(180rpx, 0, 0);
}
}
其中rpx是微信特有的屬性,不受屏幕大小的影響,類似于安卓里的dp單位。keyframes是勻速移動(dòng),從css里可以看到只改變了左右方向。
2.頭像本來想加個(gè)吊籃,像蕩秋千一樣的蕩漾,但是沒有成功,只是隨便搞了個(gè)飄來飄去的動(dòng)畫。
@keyframes pic {
0% {
transform: translate3d(0, 20rpx, 0) rotate(-15deg);
}
15% {
transform: translate3d(0, 0rpx, 0) rotate(25deg);
}
36% {
transform: translate3d(0, -20rpx, 0) rotate(-20deg);
}
50% {
transform: translate3d(0, -10rpx, 0) rotate(15deg);
}
68% {
transform: translate3d(0, 10rpx, 0) rotate(-25deg);
}
85% {
transform: translate3d(0, 15rpx, 0) rotate(15deg);
}
100% {
transform: translate3d(0, 20rpx, 0) rotate(-15deg);
}
}
沒想到keyframes不僅有支持from to還支持百分比,不錯(cuò)。這里,只要控制好層級(jí)關(guān)系、動(dòng)畫時(shí)長(zhǎng)、透明度即可實(shí)現(xiàn)云層漂浮。
不得不說css還是有很多動(dòng)畫的,也有很多特效,微信小程序里加一點(diǎn)動(dòng)畫,能使頁(yè)面稍微美觀點(diǎn)。當(dāng)然,復(fù)雜點(diǎn)的動(dòng)畫,只能有機(jī)會(huì)再更新。