1. 程式人生 > >js獲取頁面元素距離瀏覽器工作區頂端的距離

js獲取頁面元素距離瀏覽器工作區頂端的距離

獲取 fse scroll set 瀏覽器 文檔 body nbsp The

網頁被卷起來的高度/寬度(即瀏覽器滾動條滾動後隱藏的頁面內容高度)

(javascript) document.documentElement.scrollTop //firefox

(javascript) document.documentElement.scrollLeft //firefox

(javascript) document.body.scrollTop //IE

(javascript) document.body.scrollLeft //IE

(jqurey) $(window).scrollTop()

(jqurey) $(window).scrollLeft()

網頁工作區域的高度和寬度

(javascript) document.documentElement.clientHeight// IE firefox

(jqurey) $(window).height()

元素距離文檔頂端和左邊的偏移值

(javascript) DOM元素對象.offsetTop //IE firefox

(javascript) DOM元素對象.offsetLeft //IE firefox

(jqurey)

jq對象.offset().top

(jqurey) jq對象.offset().left

獲取頁面元素距離瀏覽器工作區頂端的距離

頁面元素距離瀏覽器工作區頂端的距離 = 元素距離文檔頂端偏移值 - 網頁被卷起來的高度

即:

頁面元素距離瀏覽器工作區頂端的距離 = DOM元素對象.offsetTop - document.documentElement.scrollTop

js獲取頁面元素距離瀏覽器工作區頂端的距離