gpt4 book ai didi

javascript - css 变换高度不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 21:58:09 26 4
gpt4 key购买 nike

我正在尝试为元素的高度属性设置动画,但由于某种原因它根本没有设置动画。

Here's the fiddle where I'm trying to animate.

HTML

<ul>
<li>
li 1
</li>
<li>
li 2
</li>
<li>
li 3
</li>
</ul>​

CSS

ul.hide {
height: 0px;
overflow: hidden;
}
ul {
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
}

JS:

setTimeout(function () { $('ul').addClass('hide'); }, 2000);
setTimeout(function () { $('ul').removeClass('hide'); }, 4000);​

我是否遗漏或忘记了什么?

最佳答案

我不认为如果 height 是自动的,即如果你没有明确设置它,你就不能为它设置动画。只需尝试将 height: 50px; 添加到您的 fiddle 中的 ul

改用transform: scaleY(0);!

关于javascript - css 变换高度不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12335920/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com