js中的offsetWidth用法

offsetWidth  //返回盒模型的宽度(包括width+左右padding+左右border)

<style>

#div1 { width:200px; height:200px; border:2px solid red; padding:5px; margin:1px; background:green;}

</style>

<div id="div1"></div>

以上div1的offsetWidth为width+2*padding+2*border=200+2*5+2*2=214px

ps:offsetLeft = left+margin-left

       offsetTop = top+margin-top

猜你喜欢

转载自blog.csdn.net/nuanqianxue7096/article/details/88964314