jQuery視窗 文件各種高度的理解

2021-08-27 10:09:26 字數 555 閱讀 6907

$(document).height():整個網頁的高度

$(window).height():瀏覽器可視視窗的高度

$(window).scrolltop():瀏覽器可視視窗頂端距離網頁頂端的高度(垂直偏移)

用一句話理解就是:當網頁滾動條拉到最低端時,$(document).height() == $(window).height() + $(window).scrolltop()。

當網頁高度不足瀏覽器視窗時$(document).height()返回的是$(window).height()。

不建議使用$("html").height()、$("body").height()這樣的高度。

原因:$("body").height():body可能會有邊框,獲取的高度會比$(document).height()小;

$("html").height():在不同的瀏覽器上獲取的高度的意義會有差異,說白了就是瀏覽器不相容。

$(window).height()值有問題,返回的不是瀏覽器視窗的高度?

原因:網頁沒有加上宣告。

jquery獲取文件高度和視窗高度問題

document height 整個網頁的文件高度 window height 瀏覽器可視視窗的高度 經過測試 無論是視窗高度還是文件高度 其實值是相等的。都會隨著瀏覽器視窗的縮放而變化,注意 ie8下面 獲取到的 document height 文件高度值,比實際高度多4px。比如獲取的是768p...

jquery獲取文件高度和視窗高度的例子

jquery獲取文件高度和視窗高度,document height window height document height 整個網頁的文件高度 window height 瀏覽器可視視窗的高度 window scrolltop 瀏覽器可視視窗頂端距離網頁頂端的高度 垂直偏移 document.b...

jquery獲取各種高度

alert window height 瀏覽器時下視窗可視區域高度 alert document height 瀏覽器時下視窗文件的高度 alert document.body height 瀏覽器時下視窗文件body的高度 alert document.body outerheight true ...