js中動態獲取頁面的高度和寬度的方法總結
阿新 • • 發佈:2018-11-08
javascript,jquery獲取網頁的高度和寬度:
javascript:
可視區域寬:document.documentElement.clientWidth(width+padding)
可視區域高:document.documentElement.clientHeight(height+padding)
同時也可以使用另一種進行表示:
可視區域寬:document.body.offsetWidth(包括邊線的寬:width+padding+border)
可視區域高:document.body.offsetHeight(包括邊線的高:height+padding+border)
內容高:document.body.scrollHeight
文件高:document.body.offsetHeight
縱向滾動的距離:document.body.scrollTop||document.documentElement.scrollTop
橫向滾動的距離:document.body.scrollLeft||document.documentElement.scrollLeft
jquery:
可視區域寬:$(window).width()
可視區域高:$(window).height()
頁面文件寬:$(document).width()
頁面文件高:
獲取縱向滾動條到左邊的垂直距離:$(document).scrollLeft()
獲取縱向滾動條到頂部的垂直距離:$(document).scrollTop()