首页 > 其他 > 详细

getPos封装

时间:2016-05-19 01:17:50      阅读:265      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
*{ margin:0; padding:0}
div {padding: 40px 50px;}
#div1 {background: red;position: relative;}
#div2 {background: green; position: relative;}
#div3 {background: orange; position: relative;}
</style>
<script>
window.onload = function() {
    var oDiv3 = document.getElementById(div3);
    var p = getPos( oDiv3 );
    //alert( p.left );
    alert( p.top );
    function getPos(obj) {
        var pos = {left:0, top:0};//Jason
        while (obj) {
            pos.left += obj.offsetLeft;
            pos.top += obj.offsetTop;
            obj = obj.offsetParent;
        }
        
        return pos;
        
    }
    
}
</script>
</head>

<body id="body1">
    <div id="div1">
        <div id="div2">
            <div id="div3"></div>
        </div>
    </div>
</body>
</html>

 

getPos封装

原文:http://www.cnblogs.com/Xuman0927/p/getPos.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!