我如何在 jquery 中将特定高度设置为 100%
我想对 div 中的内容进行一些“预览”,因此我将其做得很小,只显示第一行。现在我想对其进行动画处理,当您单击标题时,div 的高度将为 100%,但是当我使用 animate(height:"100%") 时,没有很好的滑动。
<a href="javascript:void(0);" class="show_it">title:</a>
<div>
content<br>
content_hidden
</div>
<script>
$('.show_it').click(function() {
$(this).next("div").animate({
height: 'auto'
}, 1000, function() {
});
});
</script>
<style>
div{
height:20px;
overflow:hidden;
}
</style>
i want to have a little "preview" of the content in the div, so i made it so small that only only the first line is shown. now i want to animate it that when you click the title, the div will have the height of 100%, but when i use animate(height:"100%") there is no nice sliding.
<a href="javascript:void(0);" class="show_it">title:</a>
<div>
content<br>
content_hidden
</div>
<script>
$('.show_it').click(function() {
$(this).next("div").animate({
height: 'auto'
}, 1000, function() {
});
});
</script>
<style>
div{
height:20px;
overflow:hidden;
}
</style>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
虽然我确信有更好的方法来做到这一点,因为这种方法充其量是马虎的,如果您找不到其他解决方案,您可以随时尝试这个:
但是,正如我所说,这非常马虎 - 如果它适合您的需求,尝试 jquery SlideDown();这是一个更好的方法。
Although I am sure there is a better way of doing this as this method is sloppy AT BEST, if you don't find another solution you could always try this:
However, as I said this is very sloppy - if it fits your needs, try jquery slideDown(); this is a much better way to do it.
或者这个:
Or this:
试试这个
Try this