Javascript 获取隐藏div的底部偏移量

Javascript 获取隐藏div的底部偏移量,javascript,jquery,Javascript,Jquery,我试图显示元素div,然后获取偏移量并再次隐藏它,还尝试在样式中保留-9999,但两者都不起作用 var spaceBelow = $(this)[0].getBoundingClientRect().bottom; console.log("Before: " spaceBelow); $(this).show(); var spaceBelow = $(this)[0].getBoundingClientRect().bottom; $(this).hide(); console.log("

我试图显示元素div,然后获取偏移量并再次隐藏它,还尝试在样式中保留-9999,但两者都不起作用

var spaceBelow = $(this)[0].getBoundingClientRect().bottom;
console.log("Before: " spaceBelow);
$(this).show();
var spaceBelow = $(this)[0].getBoundingClientRect().bottom;
$(this).hide();
console.log("After: " spaceBelow);

您提出的解决方案在Vanilla JS中对我很有效

代码:

函数运行(){
var测试=document.getElementById(“测试”);
test.style.display=“block”;
警报(test.getBoundingClientRect().bottom);
test.style.display=“无”;
}


运行
无法使用“显示:无”检索隐藏元素的位置,但可以使用属性“可见性:隐藏”。 以下是该问题的演示:

console.log($('div>div:eq(0))[0].getBoundingClientRect().bottom);
console.log($('div>div:eq(1))[0].getBoundingClientRect().bottom);
log($('div>div:eq(2)')[0].getBoundingClientRect().bottom)


@charlichthandleier和另一个div也被隐藏了,或者什么?我找到了另一种方法来找到bottom的位置。使用.height()从隐藏元素获取高度;var spacedown=$(窗口).height()-$(此).find(“隐藏”).height()-$(此)[0].getBoundingClientRect().bottom;