<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./js/jquery.min.js"></script>
<style>
.father {
width: 200px;
height: 200px;
background-color: pink;
margin-left: 100px;
margin-top: 100px;
position: relative;
}
.son {
width: 100px;
height: 100px;
background-color: red;
}
</style>
</head>
<body>
<div class="father">
<div class="son"></div>
</div>
<script>
$(function() {
//width 不受父级别影响
console.log($(".son").offset());
console.log($(".son").offset().top);
//设置
$(".son").offset({
top: 200,
left: 200
})
//只能获取 不能赋值
console.log($(".son").position())
})
</script>
</body>
</html>
运行结果
标签:jquery,console,log,top,位置,100px,son,width From: https://blog.51cto.com/u_15460007/6048628