js中动态获取页面的高度和宽度的方法总结

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).height()

获取纵向滚动条到左边的垂直距离:$(document).scrollLeft()

获取纵向滚动条到顶部的垂直距离:$(document).scrollTop()

猜你喜欢

转载自blog.csdn.net/u012994320/article/details/83105741