js中offsetWidth怎么用
创始人
2024-12-16 00:03:14
0次

  js中的offsetWidth用法

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

  

  

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

  ps:offsetLeft=left+margin-left

  offsetTop=top+margin-top

  offsetWidth与其他属性不同

  注意:下面元素属性和元素方法都通过elem.属性或elem.方法的方式使用,window属性通过window.属性的方式使用,document属性则通过document调用。