clientWidth:可视区宽       说明:样式宽+padding

clientHeight:可视区高       说明:样式高+padding

 

elem.clientWidth //获取元素的样式宽+padding

document.documentElement.clientWidth //获取文档的样式宽+padding

 

例子说明:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        #d1{width:100px;height:100px;background:red;padding:50px;margin:50px;border:10px solid black;}
    </style>
</head>
<body>
    <div id="d1"></div>
    <script>
        var dom = document.getElementById('d1');
        console.log(dom.clientWidth + ',' + dom.clientHeight);
        console.log(document.documentElement.clientWidth + ',' + document.documentElement.clientHeight);
    </script>
</body>
</html>

 

ie7/ie9:

js的client详解

相关文章:

  • 2022-01-24
  • 2022-12-23
  • 2021-08-06
  • 2021-12-23
猜你喜欢
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
相关资源
相似解决方案