獲取高度操作

2022-03-31 10:58:12 字數 1225 閱讀 8925

1、獲取div的文件總高度(必須dom操作):

var scrollheight=document.getelementbyid("inner").scrollheight;

// jq中沒有scrollheight -只有scrolltop():

// 所以用dom操作獲取元素並計算scrollheight。

2、獲取div的視窗顯示高度:

var height=$("#inner").height()

//或var height=document.getelementbyid("inner").offsetheight

3、獲取div的卷上去高度:

var scrolltop=$("#inner").scrolltop();

//或var scrolltop=document.getelementbyid("inner").scrolltop;

4、三者關係:

scrollheight >= height + scrolltop

5、獲取div距離文件(body)頂部的高度 $(「#inner」).offset().top

6、獲取div距離父元素頂部的距離 $(「#inner」).position().top

7、獲取div距離視窗(window)頂部的距離 (「#inner」).offset().top - (「body」).scrolltop()

ablue

offset()方法的定義和用法:

此方法返回或設定所匹配元素相對於document物件的偏移量。

獲取匹配元素在當前document的相對偏移。

返回的物件包含兩個整型屬:top和left。

此方法只對可見元素有效。

紅色區域的視窗高度:

不存在水平滑動時,視窗window高度 + 視窗window滾上去高度 <= 文件body總高度

同理,不存在水平滑動時,div的window高度 <= div的window高度 + div的window滾上去高度 <= 文件div的總高度

存在水平滑動時,div的window高度 <= div的window高度 + div的window滾上去高度 。

豎直滑到底部時:div的window高度 + div的window滾上去高度= 文件div的總高度+水平滾動條的高度

c距離文件body頂部距離(不變):

c距離父元素b頂部的距離(不變):

c距離視窗window頂部的距離:

body卷上去:

jq獲取頁面高度 JQuery獲取頁面高度寬度

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

獲取高度寬度

獲取瀏覽器顯示區域 可視區域 的高度 window height 獲取瀏覽器顯示區域 可視區域 的寬度 window width 獲取頁面的文件高度 document height 獲取頁面的文件寬度 document width 瀏覽器當前視窗文件body的高度 document.body hei...

獲取螢幕高度

想要網頁自適應,無論如何都要先獲取螢幕高度,給最外層的div,有利於也裡面的布局。vue中獲取螢幕寬高的方法 data 這些引數是什麼意思?根據你的需求選擇吧 window.innerwidth 瀏覽器視口 viewport 寬度 單位 畫素 如果存在垂直滾動條則包括它。document.docum...