弹跳加载器

荒凉一梦 提交于 2020-03-07 23:17:08

创建一个弹跳加载器动画。

注意:1rem通常是16px

  1. @keyframes定义一个动画,具有两个状态,元素使用opacity改变透明度,使用transform: translate3d()在 2D 平面上平移。在transform: translate3d()上使用单轴平移可提高动画的性能。
  2. .bouncing-loader是弹跳圆的父容器,使用display: flexjustify-content: center将其放置在中心。
  3. .bouncing-loader > div,以要设置样式的父级的三个子div为目标。div给定宽度和高度1rem,使用border-radius: 50%从方形转成圆。
  4. margin: 3rem 0.2rem指定每个圆的上/下边距为3rem,左/右边距为0.2rem,使得它们不会彼此直接接触,给它们提供了一些间隔。
  5. animation是对于各种动画属性的简略属性:animation-nameanimation-durationanimation-iteration-countanimation-direction
  6. nth-child(n)定位为元素的第 n 个子元素。
  7. animation-delay分别在第二个和第三个div上使用,因此每个元素不会同时启动动画。
浏览器支持

100.0%

  • https://caniuse.com/#feat=css-animation
预览

可在 CodePen 中预览

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;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!