讓我們把它帶到codez!快速瀏覽到的jQuery 1.9.1源透露:
position: function() {
if (!this[ 0 ]) {
return;
}
var offsetParent, offset,
parentOffset = { top: 0, left: 0 },
elem = this[ 0 ];
// fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is it's only offset parent
if (jQuery.css(elem, "position") === "fixed") {
// we assume that getBoundingClientRect is available when computed position is fixed
offset = elem.getBoundingClientRect();
} else {
// Get *real* offsetParent
offsetParent = this.offsetParent();
// Get correct offsets
offset = this.offset();
if (!jQuery.nodeName(offsetParent[ 0 ], "html")) {
parentOffset = offsetParent.offset();
}
// Add offsetParent borders
parentOffset.top += jQuery.css(offsetParent[ 0 ], "borderTopWidth", true);
parentOffset.left += jQuery.css(offsetParent[ 0 ], "borderLeftWidth", true);
}
// Subtract parent offsets and element margins
// note: when an element has margin: auto the offsetLeft and marginLeft
// are the same in Safari causing offset.left to incorrectly be 0
return {
top: offset.top - parentOffset.top - jQuery.css(elem, "marginTop", true),
left: offset.left - parentOffset.left - jQuery.css(elem, "marginLeft", true)
};
},
沒有參數讀取,沒有使用的參數。無論你看到那個代碼,它都不是jQuery核心。最有可能的是,因爲原作者使用了擴展該方法的jQuery UI。
感謝您的信息。你能幫我以簡短的形式瞭解這些物體的屬性嗎? – 2013-05-01 12:38:14
@Maizere爲什麼不閱讀[documentation](http://api.jqueryui.com/position/)? – undefined 2013-05-01 12:39:52
@undefined麻煩閱讀英文。不良英語 – 2013-05-01 12:40:46