jquery对象模型
来源:互联网 发布:防网络诈骗 编辑:程序博客网 时间:2024/06/06 04:48
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
.father{
margin-left: 200px;
margin-top: 100px;
position: relative;
width: 400px;
height: 400px;
background-color: yellow;
}
.son{
width: 100px;
height: 100px;
position: absolute;
left: 50px;
top: 100px;
background-color: gray;
}
</style>
</head>
<body>
<div class="father">
<div class="son"></div>
</div>
</body>
<script src="js/jquery-3.2.1.min.js" ></script>
<script type="text/javascript">
//CSS() 设置或者获取css样式
$('div').css({'color':'red'});
//获取样式
var myColor= $('div').css('color');
console.log(myColor);
//宽高 width height
console.log($('div').width());
console.log($('div').height());
//获取距离文档边缘的偏移量 offset()
var left=$('div').offset().left;
console.log(left);
var Top=$('div').offset().top;
console.log(Top);
//*距离相对定位父级的偏移量 position(); 距离父元素边缘的距离 前提是子元素相对于父元素定位;
var leftNum= $('.son').position().left;
console.log(leftNum);
//返回 最近的 定位的 祖先元素
var myElement=$('.son').offsetParent();
console.log(myElement);
</script>
</html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
.father{
margin-left: 200px;
margin-top: 100px;
position: relative;
width: 400px;
height: 400px;
background-color: yellow;
}
.son{
width: 100px;
height: 100px;
position: absolute;
left: 50px;
top: 100px;
background-color: gray;
}
</style>
</head>
<body>
<div class="father">
<div class="son"></div>
</div>
</body>
<script src="js/jquery-3.2.1.min.js" ></script>
<script type="text/javascript">
//CSS() 设置或者获取css样式
$('div').css({'color':'red'});
//获取样式
var myColor= $('div').css('color');
console.log(myColor);
//宽高 width height
console.log($('div').width());
console.log($('div').height());
//获取距离文档边缘的偏移量 offset()
var left=$('div').offset().left;
console.log(left);
var Top=$('div').offset().top;
console.log(Top);
//*距离相对定位父级的偏移量 position(); 距离父元素边缘的距离 前提是子元素相对于父元素定位;
var leftNum= $('.son').position().left;
console.log(leftNum);
//返回 最近的 定位的 祖先元素
var myElement=$('.son').offsetParent();
console.log(myElement);
</script>
</html>
阅读全文
0 0
- jquery对象模型
- 对象模型~
- 对象模型
- 对象模型
- 对象模型
- 对象模型
- 对象模型
- 对象模型
- c++对象模型-对象模型
- 源码-JavaScript&jQuery交互式前端开发-第3章-函数、方法与对象-浏览器对象模型
- 源码-JavaScript&jQuery交互式前端开发-第3章-函数、方法与对象-文档对象模型
- jQuery对象
- jquery 对象
- Jquery对象
- jquery对象
- JQuery对象
- JQuery对象
- 源码-JavaScript&jQuery交互式前端开发-第5章-文档对象模型-更新文本和标签
- 看不到git远程分支
- Biorhythms HDU
- 分布式一致性算法--Raft
- 文章标题
- vbox里面的Ubuntu虚拟机与主机win7之间设置共享文件夹
- jquery对象模型
- 【Unity与23种设计模式】解释器模式(Interpreter)
- imageloder
- fl2440 palt_button.c驱动测试
- 人工智能相关书籍资料整理
- npm慢的解决办法
- 实现代码自动打包与发布(Jenkins+Maven+Svn)
- 1073:人民币问题
- jquery-table切换