【问题标题】:Animate.css not working on hoverAnimate.css 无法悬停
【发布时间】:2017-09-26 12:50:29
【问题描述】:

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

$(document).ready(function(){

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

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

});

【问题讨论】:

    标签: jquery animate.css


    【解决方案1】:

    如果您使用的是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>

    【讨论】:

    • 这部分正确,但是当页面加载时它没有$("h1").addClass("animated zoomInDown") 动画@AVAVT
    • @user3519870 你能提供你的环境(浏览器/设备)吗?我在这里测试了 Chrome 和 Firefox,动画第一次运行良好。
    猜你喜欢
    • 1970-01-01
    • 2013-08-11
    • 1970-01-01
    • 2015-03-17
    • 2018-05-08
    • 2016-04-27
    • 2011-01-04
    • 2018-09-03
    • 1970-01-01
    相关资源
    最近更新 更多