文件高度原始高度的百分比

时间:2012-05-09 00:32:53

标签: javascript jquery dom

我希望重置原始文档的高度,以便在添加元素后删除额外的空间。我现在的代码就是这个。

    $(document).ready(function() {
       var document_height = $(document).height();
       document_height = 0.70 * document_height;
       $(document).height(document_height);
    });

这应该会改变文档高度,但不会。有更好的方法吗?

2 个答案:

答案 0 :(得分:3)

我认为您需要使用$(window)代替$(document)

$(document)表示整个文档的高度,$(window)表示视口大小。

如果确实需要降低文档对象高度的行为,可以考虑使用CSS中的替代方法来删除添加元素后的“额外空间”边距/填充。

答案 1 :(得分:0)

原始问题中的代码确实有效。其他东西正在为文档添加更多空间。