jQuery相关宽高

jQuery宽高主要方法有以下几种:

width()、height()

innerWidth()、innerHeight()

outerWidth()、outerHeight()

这些宽高都是可读写的

1.width()height()

只是content部分,不包括padding,border,margin

传入value值或function可更改宽高值

.width()与.css("width")的区别:

  • .width()的返回值没有单位。
  • .css("width")返回值有单位。

2.innerWidth()innerHeight()

包括padding

传入value值或function可更改宽高值

3.outerWidth()outerHeight()

默认包括padding和border情况, outerHeight(true)时,包括margin。

其它相关方法:

.scrollTop()、.scrollLeft()同js

.offset()、.position()

 .offset():相对于document当前坐标值(相当于body左上角的left,top)

.position():相对于offset parent的坐标值(相对于最近的祖先定位元素左上角的left,top)

原文地址:https://www.cnblogs.com/embrace-ly/p/10985777.html