一个浏览器窗口有一个window对象,javascript属于window对象,html为document对象,属于window,body为document对象,只有设置body对象高度为100%,其他地方的高度设置百分比才有效。

html和body本来高度就是0,或者说是auto的。

document.documentElement.offsetHeight,document.body.offsetHeight都是0

高度根据内容而定,设置为100%就是相对于浏览器窗口window,100%

window.innerHeight与innerWidth获取浏览器窗口内容大小。

做手机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 

Window-document-javascript的更多相关文章

  1. (function (window, document, undefined) {})(window, document)什么意思?

    1.IIFE(即时调用的函数表达式),它采取以下表达式: (function (window, document, undefined) { // })(window, document); Java ...

  2. (function($, window, document) {}) jQuery 调用解决与其他javascript库冲突的写法

    将函数包在红色字体内部,可以解决$符号与其他插件的冲突. <script type="text/javascript"> (function($, window, do ...

  3. javascript中window,document,body的解释

    解释javascript中window,document,body的区别: window对象表示浏览器中打开的窗口,即是一个浏览器窗口只有一个window对象. document对象是载入浏览器的ht ...

  4. JavaScript的DOM操作。Window.document对象

    间隔执行一段代码:window.setlnteval("需要执行的代码",间隔毫秒数) 例 :      window.setlnteval("alert("你 ...

  5. javascript匿名函数自执行 (function(window,document,undefined){})(window,document);

    使用匿名自执行函数的作用: (function(window,document,undefined){})(window,document); 1.首先匿名函数 (function(){}) (); ...

  6. 详解jquery插件中;(function ( $, window, document, undefined )的作用

    在jquery插件中我们经常看到以下这段代码 1 2 3 ;(function ( $, window, document, undefined ){ //函数体内具体代码 })(jQuery, wi ...

  7. 基本的window.document操作及实例

    基本的window.document操作及实例 找元素 1.根据id找 var d1 = document.getElementById("d1"); alert(d1); 2.根 ...

  8. Window.document对象

    1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个:     var a =docunme ...

  9. Window.document对象 轮播练习

    Window.document对象 一.找到元素:     docunment.getElementById("id"):根据id找,最多找一个:     var a =docun ...

  10. HTML Window.document对象

    1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个:    var a =docunmen ...

随机推荐

  1. pvalue for go kegg enrichment

      Simple, fast implementation of Fisher’s exact test. . For example, for the following table: o Havi ...

  2. GIL与线程、进程、协程

    GIL全局解释器锁: 1.相信大家都知道python代码是不能直接被机器cpu识别和执行的,它要经过python解释器(也就是我们执行时候的python3 name.py)被编译成机器语言,pytho ...

  3. DataGrid 扩展

    //扩展表格,支持上传附件 function extendDataGrid(){ //扩展表格方法,合并单元格 ,参数为数组 $.extend($.fn.datagrid.methods, { aut ...

  4. 用 Bitcron 搭博客:你只管写作,它负责呈现

    目录 为何要写博客 极简建站 专于写作 与微信联动 付费模式 尾巴 Bitcron 是一个可作为博客使用的互联网渲染引擎,只需网页即能工作,支持 Markdown 语法,通过 Web.微信.Dropb ...

  5. 将maven打包为一个jar(可以体外加入jar)

    使用 maven-compiler-plugin插件, 在maven的pom的<build></build>标签中上加入 <build> <plugins&g ...

  6. spring中 Bean的装配 Bean后处理器

  7. MySQL数据库篇之数据类型

    主要内容: 一.数值类型 二.日期类型 三.字符串类型 四.枚举类型与集合类型 1️⃣ 数值类型 1.整数类型:tinyint  smallint  mediumint  int  bigint 作用 ...

  8. Promethus安装指南

    由于Prometheus是go语言写的,所以不需要编译,安装的过程非常简单,仅需要解压然后运行.Prometheus官方下载地址:https://prometheus.io/download/ 安装P ...

  9. 用css实现文本不换行切超出限制时显示省略号(小tips)

    div{ max-width: 500px; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;/*文本不换行*/ } 如上 ...

  10. Python与Go斐波那契数列

    #!/usr/bin/env python # -*- coding: utf-8 -*- # 斐波那契数列 def fibonacci_sequence(num): aa = 0 b = 1 li ...