Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 文档高度占原始高度的百分比_Javascript_Jquery_Dom - Fatal编程技术网

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