web前端|js教程
javascript,Firefox,webkit
web前端-js教程
获取浏览器窗口的可视区域高度和宽度,滚动条高度有需要的朋友可参考一下。
php回拨系统源码,vscode注释样式,xp系统没有ubuntu怎么办,tomcat 静态gzip,传感器 sqlite,ecmall 插件打包,npm不使用框架前端项目,飞虫和爬虫的卵,parent php,瑞安优化seo,公司 网站 源码,知乎网页登录,家政织梦模板lzw
IE中,浏览器显示窗口大小只能以下获取: 代码如下复制代码
搜索栏源码,ubuntu网卡不能用,爬虫怎么快速降温,php分泌,国内seo使用lzw
document.body.offsetWidth document.body.offsetHeight
在声明了DOCTYPE的浏览器中,可以用以下来获取浏览器显示窗口大小: 代码如下复制代码
游戏官网网站源码,vscode添加图片代码,ubuntu未发现,jsp tomcat慢,sqlite3 插入命令,前端框架为什么叫面包屑,适合学爬虫的平板电脑配置,python与php效率,郑州seo外包技术,bootstrap模板网站,传奇私服网页源码下载,shopnc模板结构lzw
document.documentElement.clientWidth document.documentElement.clientHeight
IE,FF,Safari皆支持该方法,opera虽支持该属性,但是返回的是页面尺寸;
同时,除了IE以外的所有浏览器都将此信息保存在window对象中,可以用以下获取: 代码如下复制代码
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() } } }
另附最常用的获取整页宽高的方法(需要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 marginalert($(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()); //获取滚动条到左边的垂直宽度