jQuery 获取屏幕高度、宽度
2016-05-19 18:40
831 查看
alert($(window).height());//浏览器当前窗口可视区域高度
alert($(document).height());//浏览器当前窗口文档的高度
alert($(document.body).height());//浏览器当前窗口文档body的高度
alert($(document.body).outerHeight(true));//浏览器当前窗口文档body的总高度包括borderpaddingmargin
alert($(window).width());//浏览器当前窗口可视区域宽度
alert($(document).width());//浏览器当前窗口文档对象宽度
alert($(document.body).width());//浏览器当前窗口文档body的高度
alert($(document.body).outerWidth(true));//浏览器当前窗口文档body的总宽度包括borderpaddingmargin
//获取页面的高度、宽度
functiongetPageSize(){
varxScroll,yScroll;
if(window.innerHeight&&window.scrollMaxY){
xScroll=window.innerWidth+window.scrollMaxX;
yScroll=window.innerHeight+window.scrollMaxY;
}else{
if(document.body.scrollHeight>document.body.offsetHeight){//allbutExplorerMac
xScroll=document.body.scrollWidth;
yScroll=document.body.scrollHeight;
}else{//ExplorerMac...wouldalsoworkinExplorer6Strict,MozillaandSafari
xScroll=document.body.offsetWidth;
yScroll=document.body.offsetHeight;
}
}
varwindowWidth,windowHeight;
if(self.innerHeight){//allexceptExplorer
if(document.documentElement.clientWidth){
windowWidth=document.documentElement.clientWidth;
}else{
windowWidth=self.innerWidth;
}
windowHeight=self.innerHeight;
}else{
if(document.documentElement&&document.documentElement.clientHeight){//Explorer6StrictMode
windowWidth=document.documentElement.clientWidth;
windowHeight=document.documentElement.clientHeight;
}else{
if(document.body){//otherExplorers
windowWidth=document.body.clientWidth;
windowHeight=document.body.clientHeight;
}
}
}
//forsmallpageswithtotalheightlessthenheightoftheviewport
if(yScroll<windowHeight){
pageHeight=windowHeight;
}else{
pageHeight=yScroll;
}
//forsmallpageswithtotalwidthlessthenwidthoftheviewport
if(xScroll<windowWidth){
pageWidth=xScroll;
}else{
pageWidth=windowWidth;
}
arrayPageSize=newArray(pageWidth,pageHeight,windowWidth,windowHeight);
returnarrayPageSize;
}
//滚动条
document.body.scrollTop;
$(document).scrollTop();
源引:http://www.cnblogs.com/hoojo/archive/2012/02/16/2354663.html
相关文章推荐
- jquery移除事件
- jquery操作select(取值,设置选中)
- WebStrom 2016.1.1.破解
- jQuery入门(1) 加载事件
- jquery修改css的两种方法
- jquery的height()和javascript的height总结,js获取屏幕高度
- jquery width,innerWidth,outterWidth 及事件操作
- jQuery.html() .text()和.val() 的用法
- Jquery可移动的DIV
- JQuery为textarea添加maxlength属性并且兼容IE
- 用jQuery获取table中行id和td值的实现代码
- jQuery scrollFix滚动定位插件
- SpringMVC和jQuery的Ajax简单文件上传下载示例
- jquery遍历table的tr获取td的值实现方法
- jquery if条件语句的写法
- jquery 弹窗插件 layer
- jquery.base64.js简单使用
- jquery的ajax同步和异步
- 设置 datetimepicker 只选择日期 不选择时分秒
- jQuery 自定义事件