标签:style blog http java color strong
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
<title>offsetParent属性</title>
<style type="text/css">
div {
margin: 5px;
}
#div11 {
border: 2px solid #0000ff;
}
#div21 {
position: relative;
border: 2px solid #ffff00;
}
#div30 {
position: relative;
border: 2px solid red;
}
#div31 {
}
</style>
<script type="text/javascript">
function initPage() {
getOffsetParent('div12'); //BODY
getOffsetParent('div22');//DIV
getOffsetParent('div32');//BODY
}
function getOffsetParent(id) {
var divEl = document.getElementById(id);
var el = divEl.offsetParent;
console.log(el.nodeName);
console.log('element id is ' + el.getAttribute('id') || '');
}
</script>
</head>
<body onload="initPage()">
<div id="div11">
<div id="div12">测试1</div>
</div>
<div id="div21">
<div id="div22">测试2</div>
</div>
<div id="div30">
<div id="div31">
<div id="div32">测试3</div>
</div>
</div>
</body>
</html>js原生offsetParent解析,布布扣,bubuko.com
标签:style blog http java color strong
原文地址:http://blog.csdn.net/spy19881201/article/details/37995131