CSS动画淡出似乎不起作用

CSS animations fadeIn doesn't seem to work

本文关键字:不起作用 淡出 动画 CSS      更新时间:2023-09-26

我想在我的网页上应用一个淡出效果在我的网页内容上,但不是让淡出效果我的内容只是"隐藏"。

这是我使用的CSS:
/* make keyframes that tell the start state and the end state of our object */
@-webkit-keyframes fadeIn { from { opacity:0 !important; } to { opacity:1 !important; } }
@-moz-keyframes fadeIn { from { opacity:0 !important;  } to { opacity:1 !important; } }
@keyframes fadeIn { from { opacity:0 !important; } to { opacity:1 !important; } }

fadeIn
.fade-in {
    opacity:0;  /* make things invisible upon start */
    -webkit-animation:fadeIn ease-in 1 ;  /* call our keyframe named fadeIn, use animattion ease-in and repeat it only 1 time */
    -moz-animation:fadeIn ease-in 1 ;
    animation:fadeIn ease-in 1;
    -webkit-animation-fill-mode:forwards;  /* this makes sure that after animation is done we remain at the last keyframe value (opacity: 1)*/
    -moz-animation-fill-mode:forwards;
    animation-fill-mode:forwards;
    -webkit-animation-duration:1s ;
    -moz-animation-duration:1s ;
    animation-duration:1s ;
}
.fade-in.one {
    -webkit-animation-delay: 0.7s ;
    -moz-animation-delay: 0.7s ;
    animation-delay: 0.7s;
}

对于这段html:

<div data-role="content" id="contenidoHistoria" class="fade-in one">
        <p>Entre los melismas sonoros del rebalaje y las intrincadas calles del antiguo barrio del Perchel, y a la sombra espiritual de su Iglesia parroquial del Carmen, surgi&oacute en el a&ntilde;o 2005 el sue&ntilde;o colectivo de un grupo de j&oacutevenes de aquel barrio, que bajo el &aacutenimo y el empuje del entonces p&aacuterroco nuestro querido Manolo Segura- se propusieron poner en marcha la hoy conocida como Banda de Cornetas y Tambores de Nuestra Se&ntilde;ora del Carmen del Perchel-M&aacutelaga.</p>
    </div><!-- /content -->
</div>

如果我设置不透明度为非0。淡入{透明度:0;/*使事物在开始时不可见*/"我可以看到内容,但这当然不是我想要的。

问候。

从动画属性中移除!important。(同时删除关键帧声明下面的"fadeIn")

这是一个工作版本:

http://jsfiddle.net/x62pU/2/

我还编辑了动画声明的简写,以减少您的代码。

我让它在firefox, chrome和safari中工作。这是JSFiddle的链接。

@-webkit-keyframes fadeIn { 0% { opacity:0; } 100% { opacity:1; } }
@keyframes fadeIn { 0% { opacity:0; } 100% { opacity:1; } }
.fade-in {
    opacity:0;  /* make things invisible upon start */
    -webkit-animation: fadeIn 1s ease-in;
    animation: fadeIn  1s  ease-in;
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode:forwards;
}
.fade-in.one {
    -webkit-animation-delay: 0.7s;
    animation-delay: 0.7s;
}

希望这对你有帮助!