第一句子网 - 唯美句子、句子迷、好句子大全
第一句子网 > js/jquery获取浏览器窗口可视区域高度和宽度以及滚动条高度实现代码

js/jquery获取浏览器窗口可视区域高度和宽度以及滚动条高度实现代码

时间:2022-02-14 10:07:07

相关推荐

js/jquery获取浏览器窗口可视区域高度和宽度以及滚动条高度实现代码

web前端|js教程

浏览器高度 滚动条

web前端-js教程

获取浏览器窗口的可视区域高度和宽度,滚动条高度有需要的朋友可参考一下。

IE中,浏览器显示窗口大小只能以下获取: 代码如下复制代码

最新自动采集电影源码,ubuntu登录界面点,如何放爬虫沙,php fork 数量,seo算法博客lzw

document.body.offsetWidth document.body.offsetHeight

在声明了DOCTYPE的浏览器中,可以用以下来获取浏览器显示窗口大小: 代码如下复制代码

麻将h5源码,ubuntu文件怎么换行,tomcat固定时间执行,jsoup 爬虫示例,温泉php授权更新修复,自学seo怎么做seo顾问lzw

document.documentElement.clientWidth document.documentElement.clientHeight

IE,FF,Safari皆支持该方法,opera虽支持该属性,但是返回的是页面尺寸;

同时,除了IE以外的所有浏览器都将此信息保存在window对象中,可以用以下获取: 代码如下复制代码

asp自适应文章源码,ubuntu卸载r语言,Tomcat中的命令行,爬虫高德数据,php清空浏览器输出记录,德州seo 任lzw

window.innerWidth window.innerHeight

整个网页尺寸一般获得方法 代码如下复制代码

document.body.scrollWidth document.body.scrollHeight

屏幕分辨率高度一般获得方法 代码如下复制代码

window.screen.height window.screen.width

总结一下实例

function getViewSizeWithoutScrollbar(){//不包含滚动条 return { width : document.documentElement.clientWidth, height: document.documentElement.clientHeight } } function getViewSizeWithScrollbar(){//包含滚动条 if(window.innerWidth){ return { width : window.innerWidth, height: window.innerHeight } }else if(document.documentElement.offsetWidth == document.documentElement.clientWidth){ return { width : document.documentElement.offsetWidth, height: document.documentElement.offsetHeight } }else{ return { width : document.documentElement.clientWidth + getScrollWith(), height: document.documentElement.clientHeight + getScrollWith() } } }

IE,FireFox 差异如下:

IE6.0、FF1.06+:

clientWidth = width + padding clientHeight = height + padding offsetWidth = width + padding + border offsetHeight = height + padding + border IE5.0/5.5: clientWidth = width - border clientHeight = height - border offsetWidth = width offsetHeight = height

另附个人最常用的获取整页宽高的方法(需要jquery框架) 代码如下复制代码

$(document).width() < $(ody).width() ? $(document).width() : $(ody).width(); $(document).height() < $(ody).height() ? $(document).height() : $(ody).height();

alert($(window).height()); //浏览器时下窗口可视区域高度

alert($(document).height()); //浏览器时下窗口文档的高度

alert($(document.body).height());//浏览器时下窗口文档body的高度

alert($(document.body).outerHeight(true));//浏览器时下窗口文档body的总高度 包括border padding margin

alert($(window).width()); //浏览器时下窗口可视区域宽度

alert($(document).width());//浏览器时下窗口文档对于象宽度

alert($(document.body).width());//浏览器时下窗口文档body的高度

alert($(document.body).outerWidth(true));//浏览器时下窗口文档body的总宽度 包括border padding margin

alert($(document).scrollTop()); //获取滚动条到顶部的垂直高度

alert($(document).scrollLeft()); //获取滚动条到左边的垂直宽度

更多js/jquery获取浏览器窗口可视区域高度和宽度以及滚动条高度实现代码相关文章请关注PHP中文网!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。