• 得到当前对象在不同大小的页面中的绝对位置,及冒泡cancelBubble


    <!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 + "
    " + "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>
  • 相关阅读:
    Map 合并
    如何对hashmap按value值排序
    svn使用
    java中key-value数据有重复KEY如何存储
    linux 定时
    java 执行shell命令
    Java相对路径读取文件
    MySql之on duplicate key update详解
    前端学习资源整合
    Number浮点数运算详解
  • 原文地址:https://www.cnblogs.com/qq21270/p/3472978.html
Copyright © 2020-2023  润新知