您当前的位置: 首页 > 

暂无认证

  • 3浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

client offset详解

发布时间:2020-09-19 00:02:57 ,浏览量:3

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> *{ margin: 0; padding: 0; } div{ width: 100px; height: 100px; padding: 50px; border: 50px solid #000; background: red; background-clip: content-box; } </style> </head> <body> <div id="box"></div> <script type="text/javascript"> /*
    1.offsetWidth = 宽度 + 内边距 + 边框
     offsetHeight = 高度 + 内边距 + 边框
    2.clientWidth = 宽度 + 内边距
     clientHeight = 高度 + 内边距
    */ let oDiv = document.querySelector("div"); console.log(oDiv.clientWidth); console.log(oDiv.clientHeight); /*
    1.offsetLeft/offsetTop: 距离第一个定位祖先元素偏移位 || body
    2.clientLeft/clientTop: 左边框 和 顶部边框
    */ console.log(oDiv.clientLeft); console.log(oDiv.clientTop); </script> </body> </html> 
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.0795s