gpt4 book ai didi

javascript - 使用 CSS 动画高度

转载 作者:行者123 更新时间:2023-11-29 21:32:08 25 4
gpt4 key购买 nike

我正在尝试为未指定高度的 div 设置高度动画。我不能像许多答案建议的那样执行 max-height,因为有多个高度。

我尝试将 transition: height 0.2s ease 添加到 div,但这没有帮助。如何为高度添加动画?我非常喜欢 css,但如果那不可能,如果我完全必须使用 JavaScript,我会这样做。

JSFiddle

.tabGroup {
background-color: brown;
color: yellowgreen;
transition: height 0.2s ease;
}
.tabGroup > div {
display: none;
}
.tab1:checked ~ .tab1,
.tab2:checked ~ .tab2,
.tab3:checked ~ .tab3 {
display: block;
}
<div class="tabGroup">
<input type="radio" name="tabGroup1" id="rad1" class="tab1" checked="checked" />
<label for="rad1">Tab 1</label>

<input type="radio" name="tabGroup1" id="rad2" class="tab2" />
<label for="rad2">Tab 2</label>

<input type="radio" name="tabGroup1" id="rad3" class="tab3" />
<label for="rad3">Tab 3</label>

<div class="tab1">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<div class="tab2">
Tab 2 content
</div>
<div class="tab3">
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up
one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum
et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section
1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by
English versions from the 1914 translation by H. Rackham.
</div>
</div>

最佳答案

I can't do max-height like many answers suggest because there are multiple height amounts.

max-height 技巧是将其设置为任何内容都无法达到的值。这样所有的 div 高度都可以过渡到它们的内容高度。所以最终是否有多个高度值并不重要,只是 max-height 值设置在最高值之上。

这是我的尝试,它并不完美,但过渡就在那里。

.tabGroup > div {
max-height:0px;
transition:max-height 0.5s;
overflow:hidden;
}

.tab1:checked ~ .tab1,
.tab2:checked ~ .tab2,
.tab3:checked ~ .tab3 {
max-height:500px;
}

http://jsfiddle.net/guanzo/hgr0cd0q/4/

关于javascript - 使用 CSS 动画高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35882403/

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