animation - :hover; force entire animation 上的 css3 动画

标签 animation css

我创建了一个简单的弹跳动画,我将其应用于元素的 :hover 状态:

@keyframes bounce {
    0% {
      top: 0;
      animation-timing-function: ease-out;
    }
    17% {
      top: 15px;
      animation-timing-function: ease-in;
    }
    34% {
      top: 0;
      animation-timing-function: ease-out;
    }
    51% {
      top: 8px;
      animation-timing-function: ease-in;
    }
    68% {
      top: 0px;
      animation-timing-function: ease-out;
    }
    85% {
      top: 3px;
      animation-timing-function: ease-in;
    }
    100% {
      top: 0;
    }
}

.box:hover { 
    animation: bounce 1s;
}

动画效果很好,但当您将光标从元素上移开时它会突然停止。即使鼠标已经退出,是否有强制它继续设定的迭代次数?基本上我在这里寻找的是由 :hover 状态触发的动画。我正在寻找javascript 解决方案。无论如何,我在规范中都没有看到这样做,但也许我在这里错过了一个明显的解决方案?

这里有一个可以玩的 fiddle :http://jsfiddle.net/dwick/vFtfF/

最佳答案

恐怕解决这个问题的唯一方法是使用一些 javascript,您必须将动画添加为一个类,然后在动画结束时将其删除。

$(".box").bind("webkitAnimationEnd mozAnimationEnd animationend", function(){
  $(this).removeClass("animated")  
})

$(".box").hover(function(){
  $(this).addClass("animated");        
})

http://jsfiddle.net/u7vXT/

关于animation - :hover; force entire animation 上的 css3 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7694323/

相关文章:

javascript - Canvas 不透明 - 更改默认背景颜色

html - 中间带有纯文本的相邻 CSS 选择器仍然匹配

带有动画的 Android startActivity

html - 即使在注释掉/删除后也无法禁用 css 动画

jquery - 在其他一切之前加载本地存储保存的类

html - 在不知道宽度的情况下,仅使用 css 以绝对位置居中 div

php - 无法在 WordPress 仪表板中编辑自定义帖子类型

javascript - html2canvas 没有得到整个图像

javascript - 白色圆圈显示搜索工具栏

html - 使用 CSS 悬停时如何提高旋转动画的速度?