Javascript 从jQuery中的div高度减去
今天我有一个简短的问题。以下是我的功能:Javascript 从jQuery中的div高度减去,javascript,jquery,Javascript,Jquery,今天我有一个简短的问题。以下是我的功能: function checkheight() { var heightofdiv = $('#checkforheight').height(); $("#centeredbackground").css("min-height",heightofdiv); } 我的问题是,我想得到我的变量heightofdiv,然后用42个像素减去答案。实际上,我希望heightofdiv等于checkforheight的高度减去42像素。如果这是可能的,我们将不胜
function checkheight() {
var heightofdiv = $('#checkforheight').height();
$("#centeredbackground").css("min-height",heightofdiv);
}
我的问题是,我想得到我的变量heightofdiv,然后用42个像素减去答案。实际上,我希望heightofdiv等于checkforheight的高度减去42像素。如果这是可能的,我们将不胜感激。谢谢 你不能简单地从
$('checkforheight')中减去42。height()
是什么阻止你这么做的
$('#checkforheight').height() - 42;
这会让你找到你想要的
$(“#centeredbackground”).css(“最小高度”(heightofdiv-42)) 我不太明白…你能解释一下吗?你应该使用jquery算术插件:
var heightofdiv=$.subtract($('checkforheight').height(),42)代码>这就是我想的,但我不知道这是否是他要找的。@Eggo:不客气。如果它解决了你的问题,请考虑把它标记为“被接受”。谢谢你的帮助!
$('#checkforheight').height() - 42;