js获取盒子模型的高宽

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yin_991/article/details/86681438

dom.style.width/height 只能获取到内联样式的属性值,外部样式、内部样式的属性值是获取不到的。

dom.currentStyle.width/height        只有ie支持

window.getComputedStyle(dom).width/height   通用性好

dom.getBoundingClientRect().width/height      绝对定位获取的长度,这个方法有4个属性 top left width height ,定位原点在左上角,所以也可以获取盒子模型的高宽。

猜你喜欢

转载自blog.csdn.net/yin_991/article/details/86681438
今日推荐