2017年前端火了,微信小程序、weex、reactnative,就连支付宝也搞起了小程序,总感受这是原生要毁灭的节奏啊,我也乘热上车万一波。javascript
animation 属性是一个简写属性,用于设置六个动画属性:
值 描述
animation-name 规定须要绑定到选择器的 keyframe 名称。。
animation-duration 规定完成动画所花费的时间,以秒或毫秒计。
animation-timing-function 规定动画的速度曲线。
animation-delay 规定在动画开始以前的延迟。
animation-iteration-count 规定动画应该播放的次数。
animation-direction 规定是否应该轮流反向播放动画。css
方法特别多,本文主要用2个。前端
translate3d(1,1,0)
你能够理解为(左右,上下,大小)变化。
rotate3d(1,1,0,45deg)
java
1.两朵云除了大小和初始位置不通,其余都相同。react
.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是匀速移动,从css里能够看到只改变了左右方向。
2.头像原本想加个吊篮,像荡秋千同样的荡漾,可是没有成功,只是随便搞了个飘来飘去的动画。
小程序
@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还支持百分比,不错。这里,只要控制好层级关系、动画时长、透明度便可实现云层漂浮。微信小程序
不得不说css仍是有不少动画的,也有不少特效,微信小程序里加一点动画,能使页面稍微美观点。固然,复杂点的动画,只能有机会再更新。
转载请注明出处juejin.im/post/590aac…微信