批改状态:合格
老师批语:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery设置内联样式</title>
<style>
.box1{
width: 500px;
height: 500px;
border-radius: 20%;
background-color: paleturquoise;
position: relative;
}
.box2{
width: 200px;
height: 200px;
background-color: red;
top:100px;
left: 150px;
position: absolute;
}
</style>
</head>
<body>
<img src="img9.jpg" alt="">
<div class="box1">
<div class="box2"></div>
</div>
</body>
<script src="../jquery/jquery-3.2.1.min.js"></script>
<script>
var pic=$('img').css('width','200px')
var pic=$('img').css('width','200px').css('border-radius','50%').css('box-shadow','2px 2px 2px #888')
var pic = parseInt($('img').css('width'))
pic+=100
var pic=$('img').css('width',pic+'px')
// var pic=$('img').css('width')
// 获取图片的宽度
var pic=$('img').width()
var pic=$('img').height()
var pic=parseInt($('img').css('height'))
pic+=500
var pic=$('img').css('height',pic+'px')
// 获取图片的高度
var pic=$('img').height()
// 获取图片在文档里的偏移量
var pic=$('img').offset()
// 获取.box2的位置
var pic=$('.box2').position()
console.log(pic)
</script>
</html>点击 "运行实例" 按钮查看在线实例
总结:
设置内联样式 $('img').css('width','200px')
获取图片宽度快捷方式 $('img').width
获取图片高度快捷方式 $('img').height
获取图片偏移量 $('img').offset()
获取块.box2的位置 $('.box2').position()
手抄:


Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号