CSS3过渡效果:盒子阴影脉动

3

我想确保只有盒子阴影具有脉动效果,而不是整个按钮。

用户体验应该看到一个实心的按钮,但是盒子阴影会淡入淡出,如果这样说有意义的话。

以下是我的代码:

.gps_ring {
    border: 3px solid #999;
    -webkit-border-radius: 30px;
    height: 42px;
    width: 180px;
    background-color: blue;
    text-align: center;
    display: block;
    color: white;
    box-shadow: 0 0 17px black;
  -moz-box-shadow: 0 0 17px black;
  -webkit-box-shadow: 0 0 17px black;
    -webkit-animation: pulsate 1s ease-out;
    -webkit-animation-iteration-count: infinite; 
    opacity: 0.0
}
@-webkit-keyframes pulsate {
    0% {-webkit-transform: scale(0.1, 0.1); opacity: 0.0;}
    50% {opacity: 1.0;}
    100% {-webkit-transform: scale(1.2, 1.2); opacity: 0.0;}
}

EXAMPLE


为什么要使用-moz-box-shadow-webkit-box-shadow呢?请不要使用它们。 - vsync
Chrome自己不支持box-shadow吗? - Filth
希望这个链接对你有所帮助。 - Alex
http://caniuse.com/#search=box-shadow - vsync
3个回答

3
只需像这样简单地动画化阴影即可:

.gps_ring {
    border: 3px solid #999;
    border-radius: 30px;
    height: 42px;
    width: 180px;
    background-color: blue;
    text-align: center;
    display: block;
    color: white;
    box-shadow: 0 0 17px black;
    animation: pulsate 1s ease-out infinite;
}
@-webkit-keyframes pulsate {
    0%   { box-shadow: 0 0 0 black; }
    50%  { box-shadow: 0 0 17px black; }
    100% { box-shadow: 0 0 0 black; }
}
<div id="state" class="grid_4 alpha">
  <a href="#" class="gps_ring">Touch me</a>
</div>


0

HTML

<span class="pulse"></span>

CSS (层叠样式表)
.pulse {
  margin:80px;
  display: block;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: #cca92c;
  cursor: pointer;
  box-shadow: 0 0 0 rgba(0,0,0, 0.4);
  animation: none;
}
.pulse:hover {
  animation: pulse 2s infinite;
}

@-webkit-keyframes pulse {
  0% {
    -webkit-box-shadow: 0 0 0 0 rgba(0,0,0, 0.5);
  }
  70% {
      -webkit-box-shadow: 0 0 0 50px rgba(0,0,0, 0);
  }
  100% {
      -webkit-box-shadow: 0 0 0 0 rgba(0,0,0, 0);
  }
}
@keyframes pulse {
  0% {
    -moz-box-shadow: 0 0 0 0 rgba(0,0,0, 0.5);
    box-shadow: 0 0 0 0 rgba(0,0,0, 0.4);
  }
  70% {
      -moz-box-shadow: 0 0 0 50px rgba(0,0,0, 0);
      box-shadow: 0 0 0 50px rgba(0,0,0, 0);
  }
  100% {
      -moz-box-shadow: 0 0 0 0 rgba(0,0,0, 0);
      box-shadow: 0 0 0 0 rgba(0,0,0, 0);
  }
}

悬停效果。 CodePen: https://codepen.io/smith-harshan/pen/MWpGXeY 希望这对你有所帮助。

0

我觉得这就是你需要的。更好的解决方案 http://codepen.io/governorfancypants/pen/zvMxWm

<div class="circle">
  <div class="inner-circle"></div>
  <div class="cover-circle"></div>
</div>


.pulsating-circle {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translateX(-50%) translateY(-50%);
  width: 30px;
  height: 30px;

  &:before {
    content: '';
    position: relative;
    display: block;
    width: 300%;
    height: 300%;
    box-sizing: border-box;
    margin-left: -100%;
    margin-top: -100%;
    border-radius: 45px;
    background-color: #01a4e9;
    animation: pulse-ring 1.25s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
  }

  &:after {
    content: '';
    position: absolute;
    left: 0; 
    top: 0;
    display: block;
    width: 100%;
    height: 100%;
    background-color: white;
    border-radius: 15px;
    box-shadow: 0 0 8px rgba(0,0,0,.3);
    animation: pulse-dot 1.25s cubic-bezier(0.455, 0.03, 0.515, 0.955) -.4s infinite;
  }
}

@keyframes pulse-ring {
  0% {
    transform: scale(.33);
  }
  80%, 100% {
    opacity: 0;
  }
}

@keyframes pulse-dot {
  0% {
    transform: scale(.8);
  }
  50% {
    transform: scale(1);
  }
  100% {
    transform: scale(.8);
  }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接