I need to create and run custom css3 animation with javascript. When I need to create transition I write something like this:
element.style[Modernizr.prefixed('transform')] = 'rotateY(50deg)';
When I need animate element I should write
element.style[Modernizr.prefixed('animation')] = "'test' 2s ease-out infinite";
But I can't create keyframe for 'open' in the same way. Sure, I may write something like
document.creteElement("style").innerHTML = rule;
but this is dirty idea, so after reading programmatically changing webkit-transformation values in animation rules I write this:
var style = document.documentElement.appendChild(document.createElement("style")),
index = Modernizr._prefixes.length,
rule = "";
while(index--){
rule+="@"+Modernizr._prefixes[index]+"keyframes 'test'{ 0%{opacity:1;} 50%{opacity:0;} 100%{opacity:1;}} ";
}
style.sheet.insertRule(rule);
$(".mojo")[0].style[Modernizr.prefixed('animation')] = "'test' 2s ease-out infinite";
and get error: Uncaught Error: SYNTAX_ERR: DOM Exception 12
What I am doing wrong and how may I do this more appropriate way? This look horrible.