我怎样才能在悬停时把每个字母都用橡皮筋绑起来?目前我有它的每一个字母的颜色工作,但似乎无法使橡皮筋的效果进行。我做错什么了?
https://codepen.io/MariusZMM/pen/aPLJGo

.a {
  animation-duration: 1s;
  animation-fill-mode: both;
  animation-iteration-count: 1;
}

.a:hover {
  color: orange;
  /* animation: rubberBand 5s infinite; */
  animation-name: rubberBand;
}

@keyframes rubberBand {
  from {
    transform: scale3d(1, 1, 1);
  }

  30% {
    transform: scale3d(1.25, 0.75, 1);
  }

  40% {
    transform: scale3d(0.75, 1.25, 1);
  }

  50% {
    transform: scale3d(1.15, 0.85, 1);
  }

  65% {
    transform: scale3d(.95, 1.05, 1);
  }

  75% {
    transform: scale3d(1.05, .95, 1);
  }

  to {
    transform: scale3d(1, 1, 1);
  }
}

最佳答案

另一个答案的修改版本,使用内联块(与某些浏览器不兼容,但允许较少的标记):

.a {
  animation-duration: 1s;
  animation-fill-mode: both;
  animation-iteration-count: 1;
  display: inline-block;
}

.a:hover {
  color: orange;
  /* animation: rubberBand 5s infinite; */
  animation-name: rubberBand;
}

@keyframes rubberBand {
  from {
    transform: scale3d(1, 1, 1);
  }

  30% {
    transform: scale3d(1.25, 0.75, 1);
  }

  40% {
    transform: scale3d(0.75, 1.25, 1);
  }

  50% {
    transform: scale3d(1.15, 0.85, 1);
  }

  65% {
    transform: scale3d(.95, 1.05, 1);
  }

  75% {
    transform: scale3d(1.05, .95, 1);
  }

  to {
    transform: scale3d(1, 1, 1);
  }
} 

  <div class="title">
    <h1>
    <span class="a" >T</span>
    <span class="a" >E</span>
    <span class="a" >S</span>
    <span class="a" >T</span>
  </h1>
  </div>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

关于javascript - 悬停时每个字母的橡皮筋,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53961775/

10-13 00:29