【发布时间】:2016-06-12 05:39:59
【问题描述】:
当我单击切换按钮并隐藏 div 时,它会突然关闭而没有褪色动画。我怎么了?
我也想隐藏带有淡入淡出效果的 div。错过了什么?
CSS:
@-webkit-keyframes fadeIn { from { opacity:0; opacity: 1\9; /* IE9 only */ } to { opacity:1; } }
@-moz-keyframes fadeIn { from { opacity:0; opacity: 1\9; /* IE9 only */ } to { opacity:1; } }
@keyframes fadeIn { from { opacity:0; opacity: 1\9; /* IE9 only */ } to { opacity:1; } }
.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.2s;
-moz-animation-delay: 0.2s;
animation-delay: 0.2s;
}
HTML:
<a onclick="toggle_visibility('foo');">Toggle Foo</a>
<div id="foo" style="display:none;" class="fade-in one">
Here I am toggling the display text
</div>
Javascript:
<script type="text/javascript">
<!--
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'none')
e.style.display = 'block';
else
e.style.display = 'none';
}
//-->
</script>
【问题讨论】:
-
display不是动画或过渡属性。 -
好的。您能想到的任何其他技术可以实现这一目标吗?我只是想用一点动画来切换一个 div。
标签: javascript html css css-transitions