2019-07-06
描述
创建一个弹跳的加载动画。
HTML
<div class="bouncing-loader">
<div></div>
<div></div>
<div></div>
</div>
CSS
@keyframes bouncing-loader {
to {
opacity: 0.1;
transform: translate3d(0, -1rem, 0);
}
}
.bouncing-loader {
display: flex;
justify-content: center;
}
.bouncing-loader > div {
width: 1rem;
height: 1rem;
margin: 3rem 0.2rem;
background: #8385aa;
border-radius: 50%;
animation: bouncing-loader 0.6s infinite alternate;
}
.bouncing-loader > div:nth-child(2) {
animation-delay: 0.2s;
}
.bouncing-loader > div:nth-child(3) {
animation-delay: 0.4s;
}
Demo
说明
注意: 1rem 通常等于 16px.
@keyframes定义了有两个状态的动画,修改元素的opacity和使用transform: translate3d()使其在 2D 平面上进行向上的移动。在transform: translate3d()上使用一个轴的移动来改进移动的性能。.bouncing-loader是弹跳圆圈的父容器,使用display: flex和justify-content: center可以让他们剧中。.bouncing-loader > div是父元素下的三个div子元素的样式。这三个div的宽度和高度都是1rem,使用border-radius: 50%可以让他们从正方形转换为圆形。margin: 3rem 0.2rem指定每一个圆的上下边距为3rem,左右边距为0.2rem。这样他们彼此就拥有了呼吸的空间,就不会挤在一起了。animation属性是animation-name,animation-duration,animation-timing-function,animation-delay,animation-iteration-count,animation-direction,animation-fill-mode和animation-play-state属性的一个简写属性形式。nth-child(n)是父元素中的第 n 个子元素animation-delay分别用于第二个和第二个div,这样一来,元素之间的动画开始时间就不会相同。
浏览器支持
支持率:97.4%
支持情况:https://caniuse.com/#feat=css-animation
ME!
链滴