gpt4 book ai didi

jquery - 无法将 maxHeight 添加到函数中以添加和调整类的高度

转载 作者:行者123 更新时间:2023-11-28 01:09:57 27 4
gpt4 key购买 nike

我的目标是使用 .pane-documentation-tree-menu 类调整 div 的大小。我已经实现了这一点,但只有固定高度,如果我尝试添加 ma​​xHeight 它不起作用。

代码如下:

  $(document).ready(function () {
$('.pane-documentation-tree-menu').height(($(window).height() - 150 + "px"));
$(window).resize(function () {
$('.pane-documentation-tree-menu').height(($(window).height() - 150 + "px"));
});
});

背景:我一直在寻找这个问题的解决方案并在这里遇到这篇文章 Jquery problem with height() and resize()它起作用了,但是当我尝试添加 maxHeight 时它停止工作了。

最佳答案

如果你想同时设置高度和最大高度,你可以简单地使用 jQuery CSS,像这样:

function setMaxHeight() {
var windowHeight = $(window).height();
$('.pane-documentation-tree-menu').css({
'max-height': windowHeight - 150,
'height': windowHeight - 150
});
}

$(document).ready(function(){
setMaxHeight();
});

$(window).on('resize', function(){
setMaxHeight();
});

关于jquery - 无法将 maxHeight 添加到函数中以添加和调整类的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52155270/

27 4 0
文章推荐: css - 如何格式化
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com