
如果你要获取包括上述某部分在内的高度,请使用innerHeight()和outerHeight()。该函数属于jQuery对象(实例),并且对不可见的元素依然有效)
jQuery.fn.innerHeight([ value ])(设置或返回当前匹配元素的内高度。该高度值包括内边距(padding),但不包括元素的外边距(margin)、边框(border)等部分的高度。如下图:

该函数属于jQuery对象(实例),并且对不可见的元素依然有效)
jQuery.fn.outerHeight([includeMargin])(设置或返回当前匹配元素的外高度。该高度值包括内边距(padding) 、边框(border),但不包括元素的外边距(margin)部分的高度。你也可以指定参数为true,以包括外边距(margin)部分的高度如下图:

该函数属于jQuery对象(实例),并且对不可见的元素依然有效)
jQuery.fn.width([ value ])(描述:略)
jQuery.fn.innerWidth ([ value ])(描述:略)
jQuery.fn.outerWidth ([includeMargin])(描述:略)
借用孤月蓝风上色的详解图

接下来分析部分函数。
a.jQuery.fn.offset分析
offset获取的方法如下(以top为例):
offset.top = elem距浏览器视窗顶部的位置 + 文档顶部被卷起来的部分 – elem距离父元素上边框高度top。
jQuery处理就变成了:
box = elem.getBoundingClientRect();offset.top = box.top + ( win.pageYOffset || docElem.scrollTop ) - ( docElem.clientTop || 0 );这里面IE8-和IE9+等现代浏览器有个差别,使用document.documentElement.getBoundingClientRect();IE8-的top/left值为-2px;其他现代浏览器top/left值为0px;可以看出IE8-浏览器是以窗口的(2,2)坐标为原点坐标的。
var curElem = jQuery( elem ),curOffset = curElem.offset(),curCSSTop = jQuery.css( elem, "top" ),props = {}, curPosition = {}, curTop;//如果top值为auto且position为absolute或fixed则需要计算当前elem的css特征top的值if ( calculatePosition ) {curPosition = curElem.position();curTop = curPosition.top;} else {curTop = parseFloat( curCSSTop ) || ;}if ( options.top != null ) {props.top = ( options.top - curOffset.top ) + curTop;}curElem.css( props );b.jQuery.fn.positionvar offsetParent, offset,parentOffset = { top: 0, left: 0 },elem = this[ 0 ];//当元素为fixed定位是他的被定位的祖辈元素是window视窗(parentOffset = {top:0, left: 0}if ( jQuery.css( elem, "position" ) === "fixed" ) {//假设getBoundingClientRect可用offset = elem.getBoundingClientRect();} else {//获取offsetParentoffsetParent = this.offsetParent();// Get correct offsetsoffset = this.offset();if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {parentOffset = offsetParent.offset();}//增加边框parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );}return {top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true )}; 里面jQuery.fn.offsetParent()函数获取最近的祖先定位元素。 offsetParent: function() {return this.map(function() {var offsetParent = this.offsetParent || document.documentElement;while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position") === "static" ) ) {offsetParent = offsetParent.offsetParent;}return offsetParent || document.documentElement;});}c.jQuery.fn.scrollLeft和jQuery.fn.scrollTop