簡體   English   中英

CSS動畫不起作用

[英]CSS animations not working

我有一個簡單的CSS動畫可以淡入文本:

#title{
    animation: text 2s;
    -webkit-animation: text 2s;
    -moz-animation: text 2s;
    -o-animation: text 2s;
    font-family: 'Lato300', sans-serif;
    height: 115px;
    position: absolute;
    bottom: -10px;
    left: 0;
    right: 0;
    margin-bottom: auto;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
}

@keyframes text{
    0% {display: none;}
    100% {display: inline;}
}

@-moz-keyframes text{
    0% {display: none;}
    100% {display: inline;}
}

@-webkit-keyframes text{
    0% {display: none;}
    100% {display: inline;}
}

@-o-keyframes text{
        0% {display: none;}
    100% {display: inline;}
}

HTML:

<div id="title"><h1>Text goes here</h1></div>

由於某些原因,動畫無法播放。 有人知道為什么嗎? (我保留了所有代碼,以防其他原因引起問題)

您將無法為display媒體資源設置動畫。 但是,您可以轉換opacity

@-webkit-keyframes text {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

http://jsfiddle.net/5FCZA/

shake
 @-webkit-keyframes text {
    0%, 100% {-webkit-transform: translateX(0);}
    10%, 30%, 50%, 70%, 90% {-webkit-transform: translateX(-10px);}
    20%, 40%, 60%, 80% {-webkit-transform: translateX(10px);}
} 

or rotate
@-webkit-keyframes text {
    0% {-webkit-transform: scale(1);}   
    10%, 20% {-webkit-transform: scale(0.9) rotate(-3deg);}
    30%, 50%, 70%, 90% {-webkit-transform: scale(1.1) rotate(3deg);}
    40%, 60%, 80% {-webkit-transform: scale(1.1) rotate(-3deg);}
    100% {-webkit-transform: scale(1) rotate(0);}
}

對於以后遇到類似問題的任何人,我通過添加

display:block

對於翼展我試圖動畫

暫無
暫無

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

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