JQ的尺寸类

2023-05-12,

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.box{width:100px;height:100px;padding: 10px;border: solid 20px black;margin: 30px;position: absolute;left: 40px;top: 40px;overflow: auto;}
</style>
</head>
<body>
<div class="box">
width() height() innerWidth() 包含内边距(padding) outerWidth()包含内边距和边框( padding border) offset() 获取某个元素相对于浏览器窗口(可视区域的距离) position()获取某个元素相对于父元素的偏移距离 scrollTop()获取垂直滚动条的值; scrollTop(value)设置垂直滚动条的值; scrollLeft()获取水平滚动条的值; scrollLeft(value)设置水平滚动条的值;
</div>
</body>
<script src="../jquery.js"></script>
<script>
// 获取设置都可
console.log($(".box").width()) //content 100
console.log($(".box").innerWidth()) //content+padding 120
console.log($(".box").outerWidth()) //content+padding+border 160 // $(".box").width(200) //设置为200 // 只能获取不能设置
console.log($(".box").offset()) //position+margin l:70 t:70
console.log($(".box").position()) //position l:40 t:40
// $(".box").position({
// left:100,
// top:100
// }) //不能设置 没有用 $(document).click(function(){
console.log($(".box").scrollTop()) //输出滚动条距离
$(".box").scrollTop(333) //设置距离高度
}) </script>
</html>

JQ的尺寸类的相关教程结束。

《JQ的尺寸类.doc》

下载本文的Word格式文档,以方便收藏与打印。