您当前的位置: 首页 >  ar

暂无认证

  • 6浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

offsetParent

发布时间:2020-09-19 00:02:41 ,浏览量:6

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>55-JavaScript-offsetParent</title> <style> *{ margin: 0; padding: 0; } .grand-father{ width: 300px; height: 300px; margin-top: 100px; margin-left: 100px; background: deeppink; overflow: hidden; position: relative; } .father{ width: 200px; height: 200px; margin-top: 100px; margin-left: 100px; background: blue; overflow: hidden; /*position: relative;*/ } .son{ width: 100px; height: 100px; margin-top: 100px; margin-left: 100px; background: red; } </style> </head> <body> <div class="grand-father"> <div class="father"> <div class="son"></div> </div> </div> <script> /*
    1.offsetParent作用
    获取元素的第一个定位祖先<<<元素>>>
    如果没有祖先元素是定位的, 那么就是获取到的就是body
    */ let oSDiv = document.querySelector(".son"); oSDiv.onclick = function () { console.log(oSDiv.offsetParent); } </script> </body> </html> 
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.1092s