【发布时间】:2020-05-26 19:24:35
【问题描述】:
当您单击链接时,在显示/隐藏切换期间应用任何 CSS 动画。切换有效,但未应用动画。
$('.working-hours-link').click(function(e) {
$(this).siblings(".hours").toggleClass('hidden shown');
});
.hidden {
background-color: #fff;
color: #000;
-webkit-transition: all 1s;
-moz-transition: all 1s;
-o-transition: all 1s;
transition: all 1s;
display: none;
}
.shown {
background-color: #000;
color: #fff;
-webkit-transition: all 1s;
-moz-transition: all 1s;
-o-transition: all 1s;
transition: all 1s;
display: block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a class="working-hours-link" href="#">Show working hours</a>
<br>
<div class="hours hidden">
Sunday: 12:00 pm-6:00 pm
</div>
【问题讨论】:
-
您希望看到哪种过渡?颜色和背景实际上是褪色的,但显示属性就像一个开关一样运行。也许您期望不透明度过渡(从 0 到 1)?
-
CSS转换不适用于display属性。这里有一些alternatives。 -
这能回答你的问题吗? Transitions on the CSS display property
标签: javascript jquery html css