繁体   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