第一篇就先講講Javascript中的offsetParent屬性吧。 支持的瀏覽器:Internet Explorer 4.0+,Mozilla 1.0+,Netscape 6.0+,Opera 7.0+,Safari 1.0+ element.offsetParent Summary offsetParent returns a reference to the object which is the closest (nearest in the containment hierarchy) positioned containing element. If the element is non-positioned, the root element (html in standards compliant mode; body in quirks rendering mode) is the offsetParent. offsetParent returns null when the element has style.display set to "none". Syntax parentObj = element.offsetParent Parameters · parentObj is an object reference to the element in which the current element is offset. Specification DOM Level 0. Not part of specification. 節(jié)選自Mozilla Developer Center網(wǎng)站 翻譯如下: element.offsetParent 總結(jié) offsetParent屬性返回一個對象的引用,這個對象是距離調(diào)用offsetParent的元素最近的(在包含層次中最靠近的),并且是已進行過CSS定位的容器元素。 如果這個容器元素未進行CSS定位, 則offsetParent屬性的取值為根元素(在標(biāo)準(zhǔn)兼容模式下為html元素;在怪異呈現(xiàn)模式下為body元素)的引用。 當(dāng)容器元素的style.display 被設(shè)置為 "none"時(譯注:IE和Opera除外),offsetParent屬性 返回 null 。 句法 parentObj = element.offsetParent 變量 · parentObj 是一個元素的引用,當(dāng)前元素的偏移量在其中計算。 規(guī)范 DOM Level 0. 并非規(guī)范的一部分.