[英]Setting animation-delay in Safari overwrites animation property, but not in Chrome
Note, I am using the latest Safari (9.0.2) and the latest Chrome.
注意,我使用的是最新的Safari(9.0.2)和最新的Chrome。 I know that as of 9.0.x safari handles a lot more of the animation prefixes for you.
我知道从9.0.x开始,safari会为你处理更多的动画前缀。 Yay!
好极了! Also, I've submitted a bug report.
另外,我提交了一份错误报告。
At it's most simplest, I'm trying to set the animation-delay
only using JavaScript for a CSS Keyframe animation. 在这是最简单的,我试图仅使用JavaScript为CSS关键帧动画设置
animation-delay
。 The code is as follows: 代码如下:
el.style.setProperty("-webkit-animation-delay", "5s", "important");
Now in Chrome, this updates the animation-delay
property as I expect only . 现在在Chrome中,这将更新
animation-delay
,因为我只想到财产。 The animation
property is left untouched, which is what I want: animation
属性保持不变,这就是我想要的:
In Safari, however, this overwrites the animation
property, which for my purposes is not okay: 但是,在Safari中,这会覆盖
animation
属性,这对我来说不合适:
Obviously that's not even a valid animation value. 显然,这甚至不是一个有效的动画价值。 I basically want this working in Safari without overriding the
animation
property. 我基本上希望这在Safari中工作而不会覆盖
animation
属性。 Is there an alternative method to achieve this? 有没有其他方法来实现这一目标?
The idea from the CSS / HTML room was to add the class to the CSS and then just toggle it with classList.toggle
, however this animation delay property will be dynamic and repeatedly changed. CSS / HTML会议室的想法是将类添加到CSS中,然后只使用
classList.toggle
切换它,但是这个动画延迟属性将是动态的并且会反复更改。 These values are NOT known beforehand . 这些值事先不知道 。
JSFiddle: https://jsfiddle.net/swakq13a/3/ JSFiddle: https ://jsfiddle.net/swakq13a/3/
EDIT - I just saw that this question was a year old. 编辑 - 我刚看到这个问题已经有一年了。 This answer should help anyone Googling for this exact issue, apologies if it is a year too late for you, Jimbo.
这个答案可以帮助任何人谷歌搜索这个确切的问题,道歉,如果你这一年为时已晚,Jimbo。
I was able to resolve the issue in Safari (while keeping everything functional) by just resetting the entire animation property with shorthand. 通过简单地重置整个动画属性,我能够在Safari中解决问题(同时保持一切正常)。 This might not be 100% ideal, but it does circumvent the Safari bug without creating any animation issues that I can see.
这可能不是100%理想,但它确实绕过Safari bug而不会产生任何我能看到的动画问题。
Here is an example JS Fiddle showing it with a variable value: https://jsfiddle.net/andrewborem/5rb5ybe3/1/ 这是一个JS Fiddle示例,它显示了一个变量值: https : //jsfiddle.net/andrewborem/5rb5ybe3/1/
NOTE - I removed the "important" argument on setProperty since it is no longer necessary. 注 - 我删除了setProperty上的“重要”参数,因为不再需要它。 Additionally, I removed the
animation-delay
property from the CSS. 另外,我从CSS中删除了
animation-delay
属性。
setTimeout(function() {
var box = document.querySelector('#box');
var variableDelay = "5s";
box.style.setProperty("animation", "cycle-wide 2s " + variableDelay + " ease-in-out infinite both");
alert(box.style.animation);
}, 1000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.