Jquery 奇怪的最小高度行为
我正在努力解决以下jquery最小高度问题。 我有四个切换的div和一个footer都工作正常,但最小高度不在我的控制范围内。以下是jquery代码:Jquery 奇怪的最小高度行为,jquery,Jquery,我正在努力解决以下jquery最小高度问题。 我有四个切换的div和一个footer都工作正常,但最小高度不在我的控制范围内。以下是jquery代码: $(document).ready(function () { $(".btn-toggle").click(function () { var bodyHeight = parseInt($(this).parents(".container-wrapper").css('min-height'));
$(document).ready(function () {
$(".btn-toggle").click(function () {
var bodyHeight = parseInt($(this).parents(".container-wrapper").css('min-height'));
var linkHeight = $(this).siblings('p.matter').height();
var addHeight = bodyHeight + linkHeight;
var subHeight = bodyHeight - linkHeight;
var isOpen = false;
if ($(this).siblings("p.matter").css("display") !== "none") {
isOpen = true;
}
$("p.matter").slideUp();
if (isOpen) {
$(this).parents(".container-wrapper").css('min-height', subHeight);
$(this).siblings("p.matter").slideUp();
} else {
$(this).parents(".container-wrapper").css('min-height', addHeight);
$(this).siblings("p.matter").slideDown();
}
});//click fn end
});//document end
为了你的方便,我做了一份报告
感谢您的帮助
编辑1。当连续单击所有四个切换链接时,页脚会不断向下移动。
对不起,我说的是英语。将您的脚本更改为下面的脚本。您应该将父div设置为bodyheight,而不是添加heigth
很抱歉回复太晚,实际上我需要为我的项目将addHeight添加到bodyHeight。是否有其他解决方案不在else部分中将addHeight更改为bodyHeight。您的意思是用else中的linkHeight替换bodyHeight?就像这样:正是你的解决方案帮助我获得了很多新想法。。。。谢谢你的帮助。。。
$(".btn-toggle").click(function () {
var bodyHeight = parseInt($(this).parents(".container-wrapper").css('min-height'));
var linkHeight = $(this).siblings('p.matter').height();
var addHeight = bodyHeight + linkHeight;
var subHeight = bodyHeight - linkHeight;
var isOpen = false;
if ($(this).siblings("p.matter").css("display") !== "none") {
isOpen = true;
}
$("p.matter").slideUp();
if (isOpen) {
$(this).parents(".container-wrapper").css('min-height', subHeight);
$(this).siblings("p.matter").slideUp();
} else {
$(this).parents(".container-wrapper").css('min-height', bodyHeight);
$(this).siblings("p.matter").slideDown();
}
}); //click fn end