我的jQuery第九天-实例方法,位置图形
位置坐标图形大小的相关方法
- offset()
- position()
- scrollTop scrollLeft()
- width() height()
- innerWidth() outerWidth() innerHeight() outerWidth()
offset
- 会返回对象,分别记录了left 和 top距文档的距离
<style>
*{
margin: 0;
padding: 0;
}
.wrapper{
position: relative;
width: 300px;
height: 300px;
background: red;
left: 100px;
top: 100px;
}
.wrapper .demo{
position: absolute;
width: 50px;
height: 50px;
background: orange;
left: 50px;
top: 50px;
}
</style>
</head>
<div class="wrapper">
<div class="demo"></div>
</div>
<body>
<script src="./js/jquery-1.8.3.min.js"></script>
<script>
console.log($('.demo').offset({left:50,top:50}))
</script>
position()
srcollTop scrollLeft
$(window).srcollTop()
$(window).srcollLeft()
width height
innerWidth innerWidth outerWidth innerHeight outerWidth
- innerWidth会把内容和padding加进去
- outerWidth会把内容加padding和border加进去
- outerWidth可以放参数true,会把内容加padding和border和margin加进去