最近在处理拖动问题时,总算是深入探索了一下offsetParent的问题:

 

先看看定义官方定义:

 

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 offsetParentoffsetParent returns null when the element has style.display set to "none".

简单解释就是:

1. 假设结果节点的display不是none:

返回结果是一个dom节点,并且该节点具有定位属性(absolute, relative, fixed(ie7+)),如果父节点都不满足条件,则追溯到body(ie6、7在standard模式下返回html,ie在怪异模式下返回body)

 

2. 如果display是none:

在ie6、7(标准模式)(ie6、7、8怪异模式下返回)下返回满足上述条件的父节点;其他浏览器都返回undefined

 

参考:

http://www.cnblogs.com/jilleanwong/archive/2008/09/21/1295415.html

相关文章:

  • 2021-05-18
  • 2021-12-14
  • 2022-02-16
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
猜你喜欢
  • 2021-07-21
  • 2021-08-13
  • 2021-06-26
  • 2022-01-02
  • 2021-12-06
相关资源
相似解决方案