parentNode和offsetParent的区别

parentNode:直接父级

offsetParent:类似于css的包含块(根据本身定位及父级定位来确认offsetParent的目标元素)

offsetParent的作用:
    offsetLeft 和 offsetTop 是参照于offsetParent 的内边距边界的

dom里面所有元素都有offsetLeft 和 offsetTop

offsetParent兼容性:

         offsetParent(如果body和html直接的margin被清掉)
    本身定位fixed
        ==》 offsetParent:null(ie7以上不含火狐)
        ==》 offsetParent:null (火狐)
    本身定位不为fixed
        父级没有定位
        ==>offsetParent:body
        父级有定位
        ==》offsetParent:定位父级

发布了3 篇原创文章 · 获赞 0 · 访问量 31

猜你喜欢

转载自blog.csdn.net/Xiao_hello_world/article/details/104893724
今日推荐