gpt4 book ai didi

jquery - 将变量传递给 jQuery CSS 值以计算高度

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

我迫切需要将此 DIV“二”高度设置为 100% - (减去)另一个 DIV 高度(div“一”)。问题是,另一个 DIV(div“one”)的高度已经是动态的。

所以:

<body>
<div id="one"></div>
<div id="two"></div>
</body>

div { position: relative; }
body { height: 100vh; }

我尝试过类似的方法,但没有用:

$(document).ready(exe);
$(window).resize(exe);

function exe(){
var topHeight = $('#one').outerHeight(true);
$('#two').css("height", "calc(100% - topHeight)")
}

$(document).ready(exe);
$(window).resize(exe);

function exe(){
var topHeight = $('#one').outerHeight(true);
var topHeightCalc = '100%' - topHeight;
$('#two').css("height", topHeightCalc)
}

最佳答案

嘿 friend ,你也可以在不使用 calc() 函数的情况下实现你想要的。

这会获取窗口的高度并从中减去 div #one 的高度并将该高度应用到 div #two

$(document).ready(exe);
$(window).resize(exe);

function exe(){
var topHeight = $('#one').outerHeight(true);
var vhHeight = $(window).outerHeight(true);
$('#two').css("height", vhHeight - topHeight + "px");
}

关于jquery - 将变量传递给 jQuery CSS 值以计算高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35624244/

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