7.jQuery中位置坐标图形相关方法

# jQuery位置坐标图形方法

- 1.offset() 返回一个对象,包含left和top属性,当前元素相对于文档的位置
```js
$('.demo').offset();//取值
$('.demo').offset({left:100, top:100});//赋值
```

- 2.position() 返回一个对象,包含left和top属性,当前元素相对于有定位的父级元素的位置
```js
$('.demo').position();//取值
$('.demo').position({left:100, top:100});//赋值
```

- 3.scrollTop(), scrollLeft() 获取滚动条滚动过的距离
```js
$(window).scrollTop();//取值
$(window).scrollTop(100);//赋值
```

- 4.width(), height() 获取内容盒的width和height

- 5.innerWidth(), innerHeight() 获取填充盒的width和height

- 6.outerWidth(), outerHeight() 获取边框盒的width和height
```js
$('.demo').outerWidth();//获取边框盒的宽度
$('.demo').outerWidth(true);//获取content + padding + border + margin的宽度
```
以上是markdown格式的笔记
posted @ 2020-05-14 08:11  lanshanxiao  阅读(280)  评论(0编辑  收藏  举报