【发布时间】:2016-12-26 09:09:22
【问题描述】:
我的页面上有一些带有关键帧的 CSS 动画,用于淡入/淡出元素。问题是当我加载页面时会显示淡出动画。
HTML:
<button class="toggle-good">Toggle display</button>
<p class="box">I move nicely!</p>
CSS:
.box {
height: 0;
opacity: 0;
animation: FadeOut 1s ease-in-out;
}
.box.active {
height: initial;
opacity: 1;
animation: FadeIn 1s ease-in-out;
}
@keyframes FadeIn {
0% {
opacity: 0;
height: initial;
}
100% {
opacity: 1;
height: initial;
}
}
@keyframes FadeOut {
0% {
opacity: 1;
height: initial;
}
99% {
opacity: 0;
height: initial;
}
100% {
height: 0;
opacity: 0;
height: 0;
}
}
JS:
$('button').on('click', function(e) {
$(this).siblings('.box').toggleClass('active');
})
【问题讨论】:
-
从你想要做的事情来看,简单的过渡可能会更好。
-
但我想在淡出动画后将高度更改为 0。
-
查看这个答案(在提到的副本中)仅适用于 CSS:stackoverflow.com/questions/27938900/…
标签: javascript css css-animations keyframe