Width:
content padding border margin
jascript - style.width < clientWidth < offsetWidth 空
| | | |
JQ - width( ) < innerWidth( ) < outerWidth( ) < outerWidth( true )
| | | |
结果 - 100 120 130 170
-----------------------------------------------------------------------------------------------
Height:
content padding border margin
jascript - style.height < clientHeight < offsetHeight 空
| | | |
JQ - Height( ) < innerHeight( ) < outerHeight( ) < outerHeight( true )
| | | |
结果 - 100 120 130 170
*其中style.width和style.height只在有行内样式时返回100px,需要用 parseInt()把单位(px)去掉。
client = 内容+内边距;
offset = 内容+内边距+边框;
inner = 内容+内边距;
outer = 内容+内边距+边框;
outer(true) = 内容+内边距+边框+外边距;
本文详细解析了前端开发中如何准确获取元素的各种尺寸,包括内容宽度、内边距、边框及外边距等,并对比了JavaScript原生方法与jQuery插件的不同实现方式。
958

被折叠的 条评论
为什么被折叠?



