Animate.css无法悬停

时间:2017-09-26 12:50:30

标签: jquery animate.css

为什么在初始页面加载动画后,这个悬停的Animate.css动画不起作用?

$(document).ready(function(){

$("h1").addClass("animated zoomInDown")

$("h1").hover(function(){
$(this).addClass('animated shake');

});

1 个答案:

答案 0 :(得分:2)

如果您正在使用hover(),请确保您有悬停和悬停事件的处理程序。 CSS动画只有在删除后再重新运行才会重新运行:



$(document).ready(function() {

  $("h1").addClass("animated zoomInDown")

  $("h1").hover(function() {
    $(this).addClass('animated shake');
  }, function() {
    $(this).removeClass('animated shake');
  });
});

h1 {
  background: yellow;
  position: relative;
}

.animated {
  animation: animate-color 0.2s linear;
  animation-iteration-count: 5;
}

@keyframes animate-color {
  0% {
    left: 0;
  }
  50% {
    left: 5px;
    background: red;
  }
  100% {
    left: 0px;
  }
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>Hello</h1>
&#13;
&#13;
&#13;