offset取值、offset设值
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>温故而知"心"</title>
<style>
.wrapper {
position: absolute;
width: 200px;
height: 200px;
background-color: #ff0000;
left: 70px;
top: 70px;
}
.wrapper .demo {
position: absolute;
width: 100px;
height: 100px;
background-color: #0000ff;
left: 20px;
top: 20px;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="demo"></div>
</div>
</body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
console.log($('.demo').offset())
$('.demo').offset({ left: 200, top: 200 })
console.log($('.demo').offset())
</script>
</html>
position
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>温故而知"心"</title>
<style>
.wrapper {
position: absolute;
width: 200px;
height: 200px;
background-color: #ff0000;
left: 70px;
top: 70px;
}
.wrapper .demo {
position: absolute;
width: 100px;
height: 100px;
background-color: #0000ff;
left: 20px;
top: 20px;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="demo"></div>
</div>
</body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
console.log($('.demo').position())
</script>
</html>
scrollTop、scrollLeft
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>温故而知"心"</title>
<style>
.wrapper {
position: absolute;
width: 200px;
height: 200px;
background-color: #ff0000;
left: 70px;
top: 70px;
}
.wrapper .demo {
position: absolute;
width: 100px;
height: 100px;
background-color: #0000ff;
left: 20px;
top: 20px;
}
body {
width: 3000px;
height: 3000px;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="demo"></div>
</div>
</body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
</script>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>温故而知"心"</title>
<style>
.test {
width: 200px;
height: 200px;
overflow: auto;
border: 7px solid #333333;
}
.test p {
width: 3000px;
height: 3000px;
background-color: #ff0000;
}
</style>
</head>
<body>
<div class="test">
<p></p>
</div>
</body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
</script>
</html>
width、height、innerWidth、innerHeight、outerWidth、outerHeight
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>温故而知"心"</title>
<style>
.demo {
width: 200px;
height: 200px;
background-color: #ff0000;
border: 20px solid #333333;
padding: 15px;
margin: 10px;
}
</style>
</head>
<body>
<div class="demo"></div>
</body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
console.log($('.demo').width())
console.log($('.demo').height())
console.log($('.demo').innerWidth())
console.log($('.demo').innerHeight())
console.log($('.demo').outerWidth())
console.log($('.demo').outerHeight())
console.log($('.demo').outerWidth(true))
console.log($('.demo').outerHeight(true))
</script>
</html>