关于javascript:获取页面各个高度

2次阅读

共计 826 个字符,预计需要花费 3 分钟才能阅读完成。

文档底部与可视区窗口底部的间隔 = 文档总高度 – 文档滚动高度 – 可视区窗口高度
以后元素与底部的间隔 = 可视区窗口高度 + 文档滚动高度 – 以后元素与页面顶部间隔 – 以后元素高度

高度

console.log(window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0) // 文档滚动高度
    
console.log($(document).height()) // 文档总高度
    
console.log(document.documentElement.clientHeight) // 可视区窗口高度
      
console.log($('xxx').height()) // 以后元素高度
     
console.log($('xxx').offset().top) // 以后元素与页面顶部间隔

其余高度

网页可见区域宽:document.body.clientWidth
网页可见区域高:document.body.clientHeight
网页可见区域宽:document.body.offsetWidth (包含边线的宽)
网页可见区域高:document.body.offsetHeight (包含边线的宽)
网页注释全文宽:document.body.scrollWidth
网页注释全文高:document.body.scrollHeight
网页被卷去的高:document.body.scrollTop
网页被卷去的左:document.body.scrollLeft
网页注释局部上:window.screenTop
网页注释局部左:window.screenLeft
屏幕分辨率的高:window.screen.height
屏幕分辨率的宽:window.screen.width
屏幕可用工作区高度:window.screen.availHeight
屏幕可用工作区宽度:window.screen.availWidth

正文完
 0