过渡动画css3 效果+实现思路

效果图

在这里插入图片描述
项目demo链接

思路实现

/** 这里是用scss 写的 */

/** 这里让主模块高度拉满,模块占垂直水平居中 */
body {
  display: flex;
  height: 100vh;
  justify-content: center;
  align-items: center;
  background: #222;
}

.loading {
/** 颜色变量的 */
  $colors: #7ef9ff, #89cff0, #4682b4, #0f52ba, #000080;
  display: flex;
  
/** 画圆圈 */
  .dot {
    position: relative;
    width: 2em;
    height: 2em;
    margin: 0.8em;
    border-radius: 50%;
/** 主要是用来出现闪烁动画 */
    &::before {
      position: absolute;
      content: "";
      width: 100%;
      height: 100%;
      background: inherit;
      border-radius: inherit;
      animation: wave 2s ease-out infinite;
      /** 动画的循环 */
    }
/** 遍历5次,赋值背景颜色 */
    @for $i from 1 through 5 {
      &:nth-child(#{$i}) {
        background: nth($colors, $i);

        &::before {
        /** 设置动画延迟 */
          animation-delay: $i * 0.2s;
        }
      }
    }
  }
}
/** 动画效果过渡 */
@keyframes wave {
  50%,
  75% {
  /** 扩大到原来的2.5倍 */
    transform: scale(2.5);
  }

  80%,
  100% {
  /** 结束帧就透明化 */
    opacity: 0;
  }
}

转译成css版本


<div class="loading">
  <div class="dot"></div>
  <div class="dot"></div>
  <div class="dot"></div>
  <div class="dot"></div>
  <div class="dot"></div>
</div>

<style>
  body {
    display: flex;
    height: 100vh;
    align-items: center;
    justify-content: center;
    background: #222;
  }

  .loading {
    display: flex;
  }

  .loading .dot {
    position: relative;
    width: 2em;
    height: 2em;
    margin: 0.8em;
    border-radius: 50%;
  }

  .loading .dot::before {
    position: absolute;
    content: '';
    width: 100%;
    height: 100%;
    background: inherit;
    border-radius: inherit;
    animation: wave 2s ease-out infinite;
  }

  @keyframes wave {
    50%,
    75% {
      transform: scale(2.5);
    }

    80%,
    100% {
      opacity: 0;
    }
  }

  .loading .dot:nth-child(1) {
    background: #7ef9ff;
  }

  .loading .dot:nth-child(1)::before {
    animation-delay: 0.2s;
  }

  .loading .dot:nth-child(2) {
    background: #89cff0;
  }

  .loading .dot:nth-child(2)::before {
    animation-delay: 0.4s;
  }

  .loading .dot:nth-child(3) {
    background: #4682b4;
  }

  .loading .dot:nth-child(3)::before {
    animation-delay: 0.6s;
  }

  .loading .dot:nth-child(4) {
    background: #0f52ba;
  }

  .loading .dot:nth-child(4)::before {
    animation-delay: 0.8s;
  }

  .loading .dot:nth-child(5) {
    background: #000080;
  }

  .loading .dot:nth-child(5)::before {
    animation-delay: 1s;
  }
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值