Javascript 文档高度占原始高度的百分比
我想重置原始文档的高度,以便在添加元素后删除额外的空间。我现在的代码是这样的Javascript 文档高度占原始高度的百分比,javascript,jquery,dom,Javascript,Jquery,Dom,我想重置原始文档的高度,以便在添加元素后删除额外的空间。我现在的代码是这样的 $(document).ready(function() { var document_height = $(document).height(); document_height = 0.70 * document_height; $(document).height(document_height); }); 这应该会更改文档高度,但不会更改。有更好的方法
$(document).ready(function() {
var document_height = $(document).height();
document_height = 0.70 * document_height;
$(document).height(document_height);
});
这应该会更改文档高度,但不会更改。有更好的方法吗?我认为您需要使用
$(窗口)
代替$(文档)
$(文档)
表示整个文档的高度,$(窗口)
表示视口大小
如果您确实想要降低文档对象高度的行为,您可以考虑CSS中的替代品来删除在添加元素之后的“额外空间”的边距/填充。
< P>原始问题中的代码确实有效。其他一些东西正在给文档添加更多的空间。$(文档)是我要找的。我想你不是。文档是指整个文档;包括DOCTYPE
、
、
和
。