1

我昨天刚遇到animate.css,想把它应用到我的网站上。但问题是它只工作了一次,无论我在 div 上悬停多少次,它都保持不变!也许我没有正确掌握编码技术。这是我的代码:

    window.setTimeout( function(){
   $('#test').removeClass('animated bounce')},
1300);

$(function(){
    $('#test').hover(function(){
            $('#test').addClass('animated bounce');

    });
});

感谢所有的建议!

4

1 回答 1

1

尝试这个

$('#test').hover(function(){
    $(this).addClass('animated bounce');

}, function(){
    $(this).removeClass('animated-bounce');
});

甚至更好

  $('#test').hover(function(){
     $(this).addClass('animated-bounce');
  });

  var element = document.getElementById('test');
  element.addEventListener("webkitAnimationEnd", function(){
    $(element).removeClass('animated-bounce');
  }, false);

实际上。

为什么不使用只是用 css 来做

#test:hover{
   animation: animateName ....;
}

您遇到的问题是,当您添加类时,动画可以工作,但是当您第二次悬停时,它不会再次添加该类,因为它已经存在所以CSS不知道您何时悬停它而不更改类名.

链接到动画事件文档

动画结束演示

CSS :hover 演示

于 2013-07-13T16:58:29.420 回答