---- AI试用 ---域名问题某些图片和js资源无法访问,导致一些代码实例无法运行!(代码里gzui.net换成momen.vip即可)

js获取页面的各种高度大全

前端开发 蚂蚁 710℃ 0评论

1,获取屏幕的高度和宽度(屏幕分辨率):

window.screen.height

window.screen.width2,

获取屏幕工作区域的高度和宽度(去掉状态栏):

window.screen.availHeight

window.screen.availWidth

3,网页全文的高度和宽度:

document.body.scrollHeight

document.body.scrollWidth

4,滚动条卷上去的高度和向右卷的宽度:

document.body.scrollTop

document.body.scrollLeft

5,网页可见区域的高度和宽度(不加边线):

document.body.clientHeight

document.body.clientWidth

6,网页可见区域的高度和宽度(加边线):

document.body.offsetHeight

document.body.offsetWidth

// 获取窗口宽度

if (window.innerWidth)

winWidth = window.innerWidth;

else if ((document.body) && (document.body.clientWidth))

winWidth = document.body.clientWidth;

// 获取窗口高度

if (window.innerHeight)

winHeight = window.innerHeight;

else if ((document.body) && (document.body.clientHeight))

winHeight = document.body.clientHeight;

// 通过深入 Document 内部对 body 进行检测,获取窗口大小

if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth)

{

winHeight = document.documentElement.clientHeight;

winWidth = document.documentElement.clientWidth;

}

转载请注明:有爱前端 » js获取页面的各种高度大全

喜欢 (0)or分享 (0)