簡體   English   中英

啟動CSS動畫JavaScript

[英]Start CSS Animations JavaScript

如何用js啟動CSS動畫? 第一行(webkitAnimation)有效但其他行則無效。

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

為什么?

實時預覽 (點擊Ninja Star)

您最好使用該動畫創建一個單獨的類,並在需要時將其附加到您的元素:

anim_logo.setAttribute("class", yourAnimationClass);

UPDATE

要刪除新添加的類,可以使用延遲函數:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM