jQuery 获取屏幕高度、宽度的简单实现案例


Posted in Javascript onMay 17, 2016

做手机Web开发做浏览器兼容用到了,所以在网上找了些汇总下。

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 

 

// 获取页面的高度、宽度

function getPageSize() {

  var xScroll, yScroll;

  if (window.innerHeight && window.scrollMaxY) {

    xScroll = window.innerWidth + window.scrollMaxX;

    yScroll = window.innerHeight + window.scrollMaxY;

  } else {

    if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac  

      xScroll = document.body.scrollWidth;

      yScroll = document.body.scrollHeight;

    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari  

      xScroll = document.body.offsetWidth;

      yScroll = document.body.offsetHeight;

    }

  }

  var windowWidth, windowHeight;

  if (self.innerHeight) { // all except Explorer  

    if (document.documentElement.clientWidth) {

      windowWidth = document.documentElement.clientWidth;

    } else {

      windowWidth = self.innerWidth;

    }

    windowHeight = self.innerHeight;

  } else {

    if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode  

      windowWidth = document.documentElement.clientWidth;

      windowHeight = document.documentElement.clientHeight;

    } else {

      if (document.body) { // other Explorers  

        windowWidth = document.body.clientWidth;

        windowHeight = document.body.clientHeight;

      }

    }

  }    

  // for small pages with total height less then height of the viewport  

  if (yScroll < windowHeight) {

    pageHeight = windowHeight;

  } else {

    pageHeight = yScroll;

  }  

  // for small pages with total width less then width of the viewport  

  if (xScroll < windowWidth) {

    pageWidth = xScroll;

  } else {

    pageWidth = windowWidth;

  }

  arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);

  return arrayPageSize;

}

 

// 滚动条

document.body.scrollTop;

$(document).scrollTop();

以上这篇jQuery 获取屏幕高度、宽度的简单实现案例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
当前页禁止复制粘贴截屏代码小集
Jul 24 Javascript
在Linux系统中搭建Node.js开发环境的简单步骤讲解
Jan 26 Javascript
js中json处理总结之JSON.parse
Oct 14 Javascript
select下拉框插件jquery.editable-select详解
Jan 22 Javascript
js实现下拉菜单效果
Mar 01 Javascript
利用10行js代码实现上下滚动公告效果
Dec 08 Javascript
微信小程序中使用ECharts 异步加载数据实现图表功能
Jul 13 Javascript
JS Object.preventExtensions(),Object.seal()与Object.freeze()用法实例分析
Aug 25 Javascript
如何在Vue中使用CleaveJS格式化你的输入内容
Dec 14 Javascript
微信小程序云开发实现数据添加、查询和分页
May 17 Javascript
layer的prompt弹出框,点击回车,触发确定事件的方法
Sep 06 Javascript
vue v-for出来的列表,点击某个li使得当前被点击的li字体变红操作
Jul 17 Javascript
javascript css红色经典选项卡效果实现代码
May 17 #Javascript
JS获取IMG图片高宽的简单实例
May 17 #Javascript
简单的分页代码js实现
May 17 #Javascript
Js获取图片原始宽高的实现代码
May 17 #Javascript
创建一个类Person的简单实例
May 17 #Javascript
jQuery Mobile操作HTML5的常用函数总结
May 17 #Javascript
JavaScript判断页面加载完之后再执行预定函数的技巧
May 17 #Javascript
You might like
PHP 彩色文字实现代码
2009/06/29 PHP
浅谈Eclipse PDT调试PHP程序
2014/06/09 PHP
PHP Opcache安装和配置方法介绍
2015/05/28 PHP
使用PHP实现生成HTML静态页面
2015/11/18 PHP
ThinkPHP使用getlist方法实现数据搜索功能示例
2017/05/08 PHP
在PHP中输出JS语句以及乱码问题的解决方案
2019/02/13 PHP
laravel 实现根据字段不同值做不同查询
2019/10/23 PHP
关于JS管理作用域的问题
2013/04/10 Javascript
JavaScript常用全局属性与方法记录积累
2013/07/03 Javascript
javascript格式化日期时间方法汇总
2015/06/19 Javascript
jQuery 1.9.1源码分析系列(十四)之常用jQuery工具
2015/12/02 Javascript
深入理解MVC中的时间js格式化
2016/05/19 Javascript
手机图片预览插件photoswipe.js使用总结
2016/08/25 Javascript
AngularJs $parse、$eval和$observe、$watch详解
2016/09/21 Javascript
Websocket协议详解及简单实例代码
2016/12/12 Javascript
一篇文章让你彻底弄懂JS的事件冒泡和事件捕获
2017/08/14 Javascript
Node.js学习之查询字符串解析querystring详解
2017/09/28 Javascript
解决vue-quill-editor上传内容由于图片是base64的导致字符太长的问题
2018/08/20 Javascript
详解npm 配置项registry修改为淘宝镜像
2018/09/07 Javascript
基于Koa(nodejs框架)对json文件进行增删改查的示例代码
2019/02/02 NodeJs
基于Fixed定位的框选功能的实现代码
2019/05/13 Javascript
纯JS实现五子棋游戏
2020/05/28 Javascript
jQuery实现移动端扭蛋机抽奖
2020/11/08 jQuery
[03:10]超级美酒第四天 fy拉比克秀 大合集
2018/06/05 DOTA
Python实现购物车购物小程序
2018/04/18 Python
python调用摄像头显示图像的实例
2018/08/03 Python
python中使用zip函数出现错误的原因
2018/09/28 Python
Python3 元组tuple入门基础
2020/02/09 Python
TensorFlow 输出checkpoint 中的变量名与变量值方式
2020/02/11 Python
python super()函数的基本使用
2020/09/10 Python
Python中pass的作用与使用教程
2020/11/13 Python
伦敦剧院及景点门票:Encore Tickets
2018/07/01 全球购物
求职简历自荐信
2013/10/20 职场文书
秋季运动会广播稿(30篇)
2014/09/13 职场文书
2015中学教学工作总结
2015/07/22 职场文书
TypeScript 使用 Tuple Union 声明函数重载
2022/04/07 Javascript