jq获取和设置偏移量:
- js获取盒子的偏移量是:offsetLeft、offsetTop;
- jq获取盒子的偏移量的方法:offset()、position();
- offset():距离文档流左上角的left,top值,如果传参数就是设置偏移量;
- position():有定位元素的left,top值;
- offset():不传参数,就是获取距离文档流的偏移量
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./lib/jquery-3.6.1.js"></script>
<style>
*{
margin: 0%;
padding: 0%;
}
#box{
width:100px ;