CSS3组件化之圆波扩散

本篇文章主要介绍用CSS3实现的水波扩散涟漪,圆波扩散,光圈扩散,雷达波向外散发动画。

预期效果应该是这样:雷达波发散,其实应该比这个更优美,因为设计师提供的gif出现透明度丢失问题,所以建议用css3实现。

一、明确参数

1、半径

30,42,54
2、透明度

100%,50%,20%
3、颜色

#fb7070

二、实现方案

1、border-width + animation

<div parent="box">
    <a id="J_dot"></a>
</div>
div[parent="box"] {
  position: relative;
  margin:50px auto;
  width:54px;
  height: 54px;
}
#J_dot{
  float: left; 
  width: 54px;
  height: 54px;
  box-sizing: border-box;
  border-style:double; 
  border-color: #fb7070;
  border-radius: 100%;
  animation: circleAnimation 1s infinite alternate;
}

@keyframes circleAnimation {
  from {
     border-width:0;
  }
  to {
     border-width:27px;
  }
}

@-webkit-keyframes circleAnimation {
  from {
    border-width:0;
  }
  to {
    border-width:27px;
  }
}

太假了,整个动画一直固定在大圆圈内,内圆圈似乎在来回放大缩小,离期望值太远!

2、box-shadow + background-color +animation

<div parent="box">
  <div class="outer-circle">
    <div class="inner-circle"></div>
  </div>
</div>
div[parent="box"] {
  position:relative;
  margin:50px auto;
  width:54px;
  height:54px;
}
.outer-circle {
  animation: circleAnimationOut 1.5s cubic-bezier(0.165, 0.84, 0.44, 1);
}
.inner-circle {
  animation: circleAnimationIn 1.5s cubic-bezier(0.165, 0.84, 0.44, 1);
}
.outer-circle, .inner-circle {
  position: absolute;
  z-index: 10;
  width: 30px;
  height: 30px;
  background: transparent;
  border-radius: 100%;
  animation-iteration-count: infinite;
}

@keyframes circleAnimationOut {
  0% {
    box-shadow: 0 0 0 0px rgba(251, 112, 112, 0.5);
  }
  100% {
    box-shadow: 0 0 0 24px rgba(251, 112, 112, 0.2);
  }
}
@keyframes circleAnimationIn {
  0% {
    box-shadow: 0 0 0 0px rgba(251, 112, 112, 0.5);
    background-color: rgba(251, 112, 112, 1);
  }
  100% {
    box-shadow: 0 0 0 12px rgba(251, 112, 112, 0.5);
    background-color: rgba(251, 112, 112, 1);
  }
}

中间实心圆貌似没怎么动啊,效果还凑合。

3、box-shadow + transform +animation

<div parent="box">
  <div class="dot"></div>
  <div class="inner-circle"></div>
  <div class="outer-circle"></div>
</div>
@keyframes circleAnimationIn {
  0% {
    transform: scale(0.3);
    -webkit-transform: scale(0.3);
    opacity: 0.0;
  }
  25% {
    transform: scale(0.3);
    -webkit-transform: scale(0.3);
    opacity: 0.1;
  }
  50% {
    transform: scale(0.5);
    -webkit-transform: scale(0.5);
    opacity: 0.3;
  }
  75% {
    transform: scale(0.8);
    -webkit-transform: scale(0.8);
    opacity: 0.5;
  }
  100% {
    transform: scale(1);
    -webkit-transform: scale(1);
    opacity: 0.0;
  }
}
@keyframes circleAnimationOut {
  0% {
    transform: scale(0.3);
    -webkit-transform: scale(0.3);
    opacity: 0.0;
  }
  25% {
    transform: scale(0.3);
    -webkit-transform: scale(0.3);
    opacity: 0.1;
  }
  50% {
    transform: scale(0.3);
    -webkit-transform: scale(0.3);
    opacity: 0.3;
  }
  75% {
    transform: scale(0.5);
    -webkit-transform: scale(0.5);
    opacity: 0.5;
  }
  100% {
    transform: scale(0.8);
    -webkit-transform: scale(0.8);
    opacity: 0.0;
  }
}
div[parent="box"] {
  position: relative;
  margin: 50px auto;
  width: 54px;
  height: 54px;
}

/* 保持大小不变的小圆点 */
.dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 20px;
  margin-left: -9px;
  margin-top: -9px;
  -webkit-border-radius: 50%;
  -moz-border-radius: 50%;
  border-radius: 50%;
  background-color: #fb7070; /* 实心圆 ,如果没有这个就是一个小圆圈 */
  z-index: 2;
}

/* 产生动画(向外扩散变大)的圆圈 第一个圆 */
.inner-circle {
  position: absolute;
  z-index: 1;
  width: 54px;
  height: 54px;
  -webkit-border-radius: 50%;
  -moz-border-radius: 50%;
  border-radius: 50%;
  border: 1px solid #fb7070;
  -webkit-animation: circleAnimationIn 2s ease-out;
  -moz-animation: circleAnimationIn 2s ease-out;
  animation: circleAnimationIn 2s ease-out;
  -webkit-animation-iteration-count: infinite;
  -moz-animation-iteration-count: infinite;
  animation-iteration-count: infinite;
  box-shadow: 1px 1px 30px #fb7070;
}

/* 产生动画(向外扩散变大)的圆圈 第二个圆 */
.outer-circle {
  position: absolute;
  z-index: 1;
  width: 54px;
  height: 54px;
  -webkit-border-radius: 50%;
  -moz-border-radius: 50%;
  border-radius: 50%;
  border: 1px solid #fb7070;
  -webkit-animation: circleAnimationOut 2s ease-out;
  -moz-animation: circleAnimationOut 2s ease-out;
  animation: circleAnimationOut 2s ease-out;
  -webkit-animation-iteration-count: infinite;
  -moz-animation-iteration-count: infinite;
  animation-iteration-count: infinite;
  box-shadow: 1px 1px 30px #fb7070;
}

转载于:https://www.cnblogs.com/camille666/p/css3_plugins_circle_kuossan_animation.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值