<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>13_offset </title>
<style>
#box {
width:600px;
height:400px;
position: fixed;
left:50%;
top:50%;
margin:-200px 0 0 -300px;
background:#888;
}
#child {
width:200px;
height:200px;
position: relative;
left:200px;
top:100px;
background: #00bfff;
cursor: pointer;
box-shadow: 0 12px 15px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19);
}
</style>
<script src="jquery-3.6.4.min.js"></script>
</head>
<body>
<h3>offset과 position</h3>
<div id="box">
<div id="child"></div>
</div>
<script>
$("#child").click(function(){
let offset=$("#child").offset();
let position=$("#child").position();
let msg="";
msg +="offset left:"+offset.left +"<br>";
msg +="offset top:"+offset.top +"<br>";
msg +="position left:"+position.left +"<br>";
msg +="position top:"+position.top +"<br>";
$("#child").html(msg);
})
</script>
</body>
</html>