在前端jQuery代码中突然看到outerheight(),第一感觉就是,这是什么鬼?然后仔细查阅了一下,居然发现还有这么多相似的东西。

在jQuery中,获取元素高度的函数有3个,它们分别是height()、 innerHeight()、outerHeight()。

与此相对应的是,获取元素宽度的函数也有3个,它们分别是width()、 innerWidth()、outerWidth()。

它们之间有什么区别呢?以下图盒模型为例:

height():其高度范围是所匹配元素的高度height;

innerheight():其高度范围是所匹配元素的高度height+padding;

outerheight():其高度范围是所匹配元素的高度height+padding+border;

outerheight(true)其高度范围是所匹配元素的高度height+padding+border+margin;

    <div id="element" style="margin:5px; padding:10px; width:100px; height:100px; border:1px solid #000;"></div>
<script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
var $ele = $("#element"); // height() = height(100) = 100
document.writeln($ele.height()); // 100 // innerHeight() = height(100) + padding(10*2)= 120
document.writeln($ele.innerHeight()); // 120 // outerHeight() = height(100) + padding(10*2) + border(1*2) = 122
document.writeln($ele.outerHeight()); // 122 // outerHeight(true) = height(100) + padding(10*2) + border(1*2) + margin(5*2) = 132
document.writeln($ele.outerHeight(true)); // 132
</script>

水平方向上宽度大小也是如此

jQuery中的height()、innerheight()、outerheight()的区别总结的更多相关文章

  1. Jquery中的height(),innerHeight(),outerHeight()的区别

    前言 最近练习做弹窗,遇到height(),innerHeight(),outerHeight()的区别. 根据下面的盒模型来了解三者的区别. height():element的height; inn ...

  2. Jquery中的 height(), innerHeight() outerHeight()区别

    jQuery中的 height innerHeight outerHeight区别 标准浏览器下: height:高度 innerHeight:高度+补白 outerHeight:高度+补白+边框,参 ...

  3. jquery 之height(),innerHeight(),outerHeight()方法区别详解

    在jQuery中,获取元素高度的函数有3个,它们分别是height(). innerHeight().outerHeight(). 与此相对应的是,获取元素宽度的函数也有3个,它们分别是width() ...

  4. jQuery中的.height()、.innerHeight()和.outerHeight()

    jQuery中的.height()..innerHeight()和.outerHeight()和W3C的盒模型相关的几个获取元素尺寸的方法.对应的宽度获取方法分别为.width()..innerWid ...

  5. jQuery中的bind() live() delegate()之间区别分析

    jQuery中的bind() live() delegate()之间区别分析 首先,你得要了解我们的事件冒泡(事件传播)的概念,我先看一张图 1.bind方式 $('a').bind('click', ...

  6. 深入理解jQuery中live与bind方法的区别

    本篇文章主要是对jQuery中live与bind方法的区别进行了详细的分析介绍,需要的朋友可以过来参考下,希望对大家有所帮助 注意如果是通过jq添加的层和对象一定要用live(),用其他的都不起作用 ...

  7. jQuery中attr和prop方法的区别说明

    jquery中attr和prop的基本区别可以理解为:如果是内置属性,建议用prop,如果是自定义的建议用attr. 例如 <input type=check  node=123 id=ck & ...

  8. jquery中的$().each和$.each的区别

    jquery中的$().each和$.each的区别 注意:jquery中的$().each和$.each的区别,前者只能遍历数组,后者可以遍历数组和对象 备注:sinobook项目中地名本体相关地按 ...

  9. jQuery中attr和prop方法的区别

    jQuery中attr和prop方法的区别。 http://my.oschina.net/bosscheng/blog/125833 http://www.javascript100.com/?p=8 ...

  10. jquery中的this与$(this)的区别总结(this:html元素)($(this):JQuery对象)

    jquery中的this与$(this)的区别总结(this:html元素)($(this):JQuery对象) 一.总结 1.this所指的是html 元素,有html的属性,可用 this.属性  ...

随机推荐

  1. 生日蛋糕 (codevs 1710) 题解

    [问题描述] 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1<=i<=M)层蛋糕是半径为Ri,高度为Hi的圆柱 ...

  2. Python之Flask Web开发

    下载python包管理工具Pip: 访问网址:https://pip.pypa.io/en/stable/installing/    下载文件get-pip.py到本地计算机 定位到get-pip. ...

  3. Learning Scrapy笔记(七)- Scrapy根据Excel文件运行多个爬虫

    摘要:根据Excel文件配置运行多个爬虫 很多时候,我们都需要为每一个单独的网站编写一个爬虫,但有一些情况是你要爬取的几个网站的唯一不同之处在于Xpath表达式不同,此时要分别为每一个网站编写一个爬虫 ...

  4. 在Linux下JDK1.4.2安装报错的解决方法

    JDK1.4.2的安装   Do you agree to the above license terms? [yes or no]   yes   Unpacking...   tail: cann ...

  5. 'mysql.column_stats' doesn't exist and Table 'mysql.index_stats' doesn't exist

    在生产库MariabDB中修改字段类型,提示如下错误:​Table 'mysql.column_stats' doesn't existTable 'mysql.index_stats' doesn' ...

  6. Percona-Xtrabackup 2.3.3 死锁不再堵塞备份(二)

    在percona-xtrabackup2.1.9下备份: session one:root(yoon)> show tables;+----------------+| Tables_in_yo ...

  7. hdu 4308 Saving Princess claire_

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Description Princess cla ...

  8. 解压vmlinuz和解压initrd(initramfs)

    有时就算只得到一个Linux kernel的rpm包或者直接是编译后的vmlinuz和initrd的binary文件,也需要了解其中的一些细节,可能需要去查找这些binary有没有将我想要的patch ...

  9. windows phone 8.1 HttpWebRequest 请求服务器

    public string SendGetRequest(string baseurl, string parameters) { string parassb = parameters; ) { b ...

  10. C# socket 实现消息中心向消息平台 转发消息

    公司用到,直接粘代码了 using System; using System.Collections.Generic; using System.Configuration; using System ...