【问题标题】:CSS keyframes animation doesn't run in some browsersCSS 关键帧动画无法在某些浏览器中运行
【发布时间】:2015-11-05 16:29:47
【问题描述】:

我正在建立一个网站,并添加了一个 CSS 关键帧动画,通过链接点击调用(连接到一个 javascript 函数)。

这是我的 CSS 文件:

#banner {
background-color: #00BBD2;
position: absolute;
width: 100%;
height: 100%;
animation-duration: 1s;
animation-name: resizeBanner;
animation-fill-mode: forwards;
animation-play-state: paused;
}

@keyframes resizeBanner {
from {height: 100%; background-color: #00BBD2}
to {height: 30%; background-color: #009688;}
}

我正在像这样的 javascript 函数中启动动画:

<script>
    function animate()
    {
        document.getElementById('banner').style.webkitAnimationPlayState = "running";
    }
</script>

动画在某些浏览器中运行完美,而在其他浏览器中 - 它根本不运行。 怎么会这样?

但是,我在关键帧动画之后运行的 Jquery 动画始终运行。像这样调用:

$("#someid").fadeOut();

【问题讨论】:

  • 你使用webkitAnimationPlayState - 它仅适用于 CH、Opera、Safary 等 weblit 浏览器,但不适用于 FF、IE 等

标签: javascript jquery html css animation


【解决方案1】:

检查一下:

function animate() {
    // Code for Chrome, Safari, and Opera
    document.getElementById("banner").style.WebkitAnimationPlayState = "running";

    // Standard syntax
    document.getElementById("banner").style.animationPlayState = "running";
}

【讨论】:

  • 谢谢!我会尽快接受答案。为什么有两种可能?有没有优缺点?
  • 2 种可能性 - 因为现在浏览器太多了,在这部分规范中没有很多标准和 rools ......优点和缺点......嗯......我认为 2 调用是不好的对于性能,但对你来说,这是这个问题的唯一解决方法,现在。也许将来 Webkit 会在他们的浏览器中实现animationPlayState,我们将只有 1 个调用 :)
  • 嗯,但我可以单独使用标准语法吗?只需 1 次调用 - 适用于所有浏览器?
  • 不,现在animationPlayState 属性将无法在某些 webkit 浏览器中使用,但我希望将来可以:)
  • 所以你必须要么调用它们,要么检查用户当前使用的浏览器?
猜你喜欢
  • 1970-01-01
  • 2014-04-04
  • 2014-01-04
  • 2018-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多