2012-10-12 105 views
3

如何用js开始CSS动画?第一行(webkitAnimation)有效,但其他行不行。开始CSS动画JavaScript

anim_logo.style.webkitAnimation="threesixty 3s"; 
anim_logo.style.mozAnimation="threesixty 3s"; 
anim_logo.style.oAnimation="threesixty 3s"; 
anim_logo.style.animation="threesixty 3s"; 

为什么?

live preview(点击忍者星)

+0

我无法推断出一个具体的问题,但对于动画,jQuery的各种效果调用都是很好的开始... – blackcatweb

+0

@blackcatweb我可以! – 11684

+1

你可以请检查一下,如果你的第二个或最后一个如果它在Firefox中工作? – xception

回答

5

你最好做一个单独的类与动画,只是在需要的时候将其连接到您的元素:

anim_logo.setAttribute("class", yourAnimationClass); 

UPDATE

要删除新添加的类可以使用延迟功能:

function animateMe() { 
    anim_logo.setAttribute("class", yourAnimationClass); 
    setTimeout(function() { 
     anim_logo.setAttribute("class", ""); 
    }, 3000); 
} 
+1

问题是为什么他的代码只能在WebKit中工作,而不是他应该替换它。 – 11684

+0

@Zoltan Toth我会使用这个^^,如果我可以删除属性,当它完成动画。 – atomikpanda

+0

@ s0ulp1xel更新了这个想法如何在动画后删除课程 –