jQuery中offsetParent()方法用法实例
作者:bea
本文实例讲述了jQuery中offsetParent()方法用法。分享给大家供大家参考。具体分析如下: 此方法可以返回匹配元素所有祖先元素中第一个采用定位的祖先元素。 所谓采用定位的父元素就是施加position:relative或者position:absolute(fixed)的元素。 此方法仅对可见元素有效。 语法结构: 代码如下: $(selector).offsetParent() 代码实例: 代码如下: <!DOCTYPE html> &
本文实例讲述了jQuery中offsetParent()方法用法。分享给大家供大家参考。具体分析如下:
此方法可以返回匹配元素所有祖先元素中第一个采用定位的祖先元素。 所谓采用定位的父元素就是施加position:relative或者position:absolute(fixed)的元素。 此方法仅对可见元素有效。
语法结构:
代码如下:
$(selector).offsetParent()
代码实例:
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http:///" />
<title>offsetParent()函数-</title>
<style type="text/css">
.grandfather
{
width:200px;
height:200px;
background-color:red;
position:relative;
}
.father
{
width:150px;
height:150px;
background-color:blue;
}
.children
{
width:50px;
height:50px;
background-color:green;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$(".children").offsetParent().css("backgroundColor","yellow");
})
})
</script>
</head>
<body>
<div class="grandfather">
<div class="father">
<div class="children"></div>
</div>
</div>
<button>查看效果</button>
</body>
</html>
以上代码可以将children元素中所有祖先元素中,第一个采用定位的祖先元素的背景颜色设置为红色。
希望本文所述对大家的jQuery程序设计有所帮助。
本文转自:信鸽网http://www.xinge360.com/
有用 | 无用
此方法可以返回匹配元素所有祖先元素中第一个采用定位的祖先元素。 所谓采用定位的父元素就是施加position:relative或者position:absolute(fixed)的元素。 此方法仅对可见元素有效。
语法结构:
代码如下:
$(selector).offsetParent()
代码实例:
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http:///" />
<title>offsetParent()函数-</title>
<style type="text/css">
.grandfather
{
width:200px;
height:200px;
background-color:red;
position:relative;
}
.father
{
width:150px;
height:150px;
background-color:blue;
}
.children
{
width:50px;
height:50px;
background-color:green;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$(".children").offsetParent().css("backgroundColor","yellow");
})
})
</script>
</head>
<body>
<div class="grandfather">
<div class="father">
<div class="children"></div>
</div>
</div>
<button>查看效果</button>
</body>
</html>
以上代码可以将children元素中所有祖先元素中,第一个采用定位的祖先元素的背景颜色设置为红色。
希望本文所述对大家的jQuery程序设计有所帮助。
本文转自:信鸽网http://www.xinge360.com/
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- jQuery中trigger()方法用法实例
- jQuery的one()方法用法实例
- jQuery学习笔记之jQuery+CSS3的浏览器兼容性
- jQuery中bind()方法用法实例
- jQuery中on()方法用法实例
- jQuery学习笔记之创建DOM元素
- jQuery学习笔记之2个小技巧
- jQuery浏览器CSS3特写兼容实例
- jQuery自定义添加"$"与解决"$"冲突的方法
- jQuery创建DOM元素实例解析
- jQuery使用之处理页面元素用法实例
- jQuery学习笔记之jQuery中的$
- jQuery使用之设置元素样式用法实例
- jQuery学习笔记之基础中的基础
- jQuery 选择器详解
- jQuery使用之标记元素属性用法实例
- jQuery应用之jQuery链用法实例
- 浅谈Unicode与JavaScript的发展史
- jQuery中ready事件用法实例