一、client  可视区域

    offsetWidth:   width  +  padding  +  border     (披着羊皮的狼)

  clientWidth: width  +  padding      不包含border

 scrollWidth:   大小是内容的大小

二、检测屏幕宽度(可视区域)

1、ie9及其以上的版本

window.innerWidth  

2、标准模式

document.documentElement.clientWidth

3、怪异模式

document.body.clientWidth

三、window.onresize    改变窗口事件  

window.onscroll  = function() {}  屏幕滚动事件

window.onresize = function() {}  窗口改变事件

onresize 事件会在窗口或框架被调整大小时发生

 四、函数

function fun() {  语句  }

fun   是函数体的意思

fun()  调用函数 的意思

function fun() {
    return 3;
}
console.log(fun);  // 返回函数体 function fun() { retrun 3}
console.log(fun()); // 调用函数  3  返回的是结果
fun();
window.onresize = 3
window.onresize = function fun() { retrun 3}

五、检测屏幕宽度(分辨率)

clientWidth   返回的是 可视区 大小    浏览器内部的大小

window.screen.width   返回的是我们电脑的 分辨率   跟浏览器没有关系

六、封装可视区域大小的函数

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>封装可视区域大小的函数</title>
</head>
<body> </body>
</html>
<script>
function client(){
if(window.innerWidth!=null){//IE9+和最新浏览器
return{
width:window.innerWidth,
height:window.innerHeight
}
}else if(document.compatMode==="CSS1Compat"){//标准浏览器
return{
width:document.documentElement.clientWidth,
height:document.documentElement.clientHeight
} }
return{//怪异浏览器
width:document.body.clientWidth,
height:document.body.clientHeight
}
}
document.write(client().width);
</script>

最新文章

  1. Visual Studio 2013 Ultimate因为CodeLens功能导致Microsoft.Alm.Shared.Remoting.RemoteContainer.dll高CPU占用率的折中解决方案
  2. Win7+Docker(boo2docker)搭建php开发环境简略
  3. Spring urlMapping
  4. iOS开发之UITextView,设置textView的行间距及placeholder
  5. ionic 相关
  6. POJ 2315 最小费用最大流
  7. Android 自定义View修炼-仿360手机卫士波浪球进度的实现
  8. Page Object 模式编写UiAutomator脚本
  9. myisam MySQL 锁问题
  10. Java基础笔记-异常总结,包
  11. Python入门之中文乱码
  12. 产品设计-后台管理权限设计RBAC
  13. 增加删除的js
  14. js无间隙向上滚动
  15. lightoj1197 素数双筛,可以参考poj的那题双筛
  16. 数据库更新锁WITH UPDLOCK
  17. 团队项目第二周spec设计
  18. 常量引用 const T&amp;
  19. 2014.9.11 Research Meeting Report
  20. C# 把string字符导出到txt文档方法

热门文章

  1. 破解Wifi
  2. WPF 自定义ProgressBar滚动条样式
  3. 成都Uber优步司机奖励政策(1月16日)
  4. 【完美解决】Spark-SQL、Hive多 Metastore、多后端、多库
  5. Manual install on Windows 7 with Apache and MySQL
  6. unity3d 角色头顶信息3D&amp;2D遮挡解决方案(二)
  7. python3基础盲点
  8. centos下testlink的部署(基于xampp)
  9. cronolog:日志分割工具
  10. Shell 常用命令、基本用法总结