Edited - linked the wrong codepen This only seems to happen in webkit browsers. In firefox it works as intened. In IE, the right inline-style is added but it doesn't add the prefix(even if I specify 'ms-animation-delay' in the javascript instead of just 'animation-delay'
I'm playing with a codepen trying to replicate some Google Material effects ( I know they have them in polymer, I just wanted to try to replicate some of the effects for fun). For some odd reason, jQuery is wrongly putting "animation: [value]" into the inline-styling instead of "animation-delay: [value]". Can anyone explain why and how to make a work around?
Here's the codepen: link
JS:
$(document).ready(function(){
var lis = $("li"), str;
for(var x=2; x<= lis.length; x++){
str=(0.2+ 0.1*(x-2))+"s";
lis.eq(x-1).css({"animation-delay": str});
}
});
This also occurs with transition-delay.
Looks like FireFox allows you to update the animation via the sub-properties such as we can change the animation delay by just changing the property
animation-delay
. It's a pity that other browsers (Chrome, Opera, IE...) don't support that way of updating animation. That means to change the animation, you have to set theanimation-name
to a totally new name (new keyframes name). So if you just want to change theanimation-delay
, you may have to create 2 keyframes with different names (but they should have the same inner key rules, just different names). And then reapply the wholeanimation
with the new name and the desiredanimation-delay
like this:As you can see, the difference is in the name (
display2
instead ofdisplay
) and we added a delay of1s
. That way works in all browsers.However I notice that you just want to apply the animation using script, so the simplest thing to do is just remove all the animation in the CSS code (just keep the keyframes) and apply the animation using script, that way you don't need to create the clone (
display2
) ofdisplay
keyframes:Updated Demo.