继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

window.innerHeight window.outerHeight 与screen.height

程序员大阳
关注TA
已关注
手记 357
粉丝 1.5万
获赞 1523

window与screen

window是浏览器支持的全局变量,也可以通过document.defaultView获取它,表示浏览器的窗口信息。

innerHeight与outerHeight

innerHeight表示窗口内容区域的高度,这是不包括边框、菜单栏的。

而outerHeight是窗口的整体高度,包括边框、菜单栏等。

所以一般常用的是innerHeight。

screen.height

screen是指的屏幕,表示当前整个显示器显示的屏幕部分,不限于当前的窗口。height是屏幕的宽度,例如屏幕分辨率1920*1080的话,一般情况下screen.heigth即为1080。

实例

注意width相关的用法是一致的。

看下面的例子:

<html>
  <head>
    <title></title>
  </head>
  <body>
    <script>
      document.writeln("innerHeight:"+window.innerHeight);
      document.writeln("innerWidth:"+window.innerWidth);
      document.writeln("outerHeight:"+window.outerHeight);
      document.writeln("outerWidth:"+window.outerWidth);
      document.writeln("screen.height"+window.screen.height);
      document.writeln("screen.width"+window.screen.width);
    </script>
  </body>
</html>

效果如下:
在这里插入图片描述

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP