你的心如利箭 在风中笔直的飞翔
github DNS ALEXA CDN
jquery JS CSS CSS3 HTML5 svg php --- isux w3cplus

21270

  博客园  :: 首页  ::  ::  ::  :: 管理
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
function GetPosition(obj){

}
$(function(){
    $(".div1").click(function(event){
            event.stopPropagation(); 
            //var obj = $(".div1")[0];
            var obj = $(this)[0];
            var left = 0;
            var top   = 0;

            while(obj != document.body){
                left = obj.offsetLeft + left;
                top   = obj.offsetTop + top;
                obj = obj.offsetParent;
            }
            alert("Left : " + left + "\r\n" + "Top : " + top);

    });


});

</script>
<style type="text/css">
*{margin:0px;padding:0px;}
.div1{
    position:relative;
    background:#fcc;
    border-bottom:solid 1px #000;
    border-left:solid 1px #f00;
    left:200px;
}
</style>
</head>
<body>
<h3>得到当前对象在不同大小的页面中的绝对位置,及冒泡cancelBubble</h3>

<br><br><br><br>
<input type="button" value="btn" id="btn">
<div class="div1">div000
    <div class="div1">div1
    </div>
    <div class="div1">div111
    </div>
    <div class="div1">div11133
    </div>
    <div class="div1">div1114
    </div>
    <div class="div1">div1115
        <div class="div1">div111511
        </div>
        <div class="div1">div111511
        </div>

    </div>
    <div class="div1">div1116
    </div>
</div>

</body>
</html>

 

posted on 2013-12-13 14:11  bjhhh  阅读(225)  评论(0编辑  收藏  举报