一个浏览器窗口有一个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. Docker垃圾回收机制

    由Docker垃圾回收机制引发的一场血案 AlstonWilliams 关注 2017.04.01 19:00* 字数 1398 阅读 253评论 0喜欢 0 今天早晨,在我还没睡醒的时候,我们团队中 ...

  2. leetcode844

    class Solution { public: bool backspaceCompare(string S, string T) { stack<char> ST1; ; i < ...

  3. myBaits association的使用

    转自:https://blog.csdn.net/victor_cindy1/article/details/50194879 >

  4. js是函数式的面向对象编程语言

    js是函数式的面向对象编程语言,而非类式的面向对象编程语言

  5. Apache Hive (六)Hive SQL之数据类型和存储格式

    转自:https://www.cnblogs.com/qingyunzong/p/8733924.html 一.数据类型 1.基本数据类型 Hive 支持关系型数据中大多数基本数据类型 类型 描述 示 ...

  6. bootstrap-select用法详解

    首先需要引入 <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href=&quo ...

  7. VUE+WebPack前端游戏设计:实现物体的拖拽动态特效

  8. 【BZOJ1013】球形空间产生器sphere

    高斯消元模板题 #include <cstdio> #include <cstring> #include <algorithm> #include <ios ...

  9. 如何用shell脚本执行或关闭jar包服务?

    现在springboot很流行,但是大家都知道springboot是以jar包的方式进行打包的,那样就少不了开启或关闭服务的操作了,但是命令方式未免过于繁琐. 下面记录shell脚本的方式启动或关闭服 ...

  10. code3731 寻找道路

    将图反向,从终点spfa,把和终点没有联系的点找出来, 把它们和它们所连接的所有点删去(反向图) 然后再一遍spfa,输出最短路即可 代码: #include<iostream> #inc ...