Js和JQ求对象尺寸的几个方法

xiaoxiao2021-02-28  80

                                               

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) = 内容+内边距+边框+外边距;

 

转载请注明原文地址: https://www.6miu.com/read-64316.html

最新回复(0)