页面坐标位置

2017-06-19 11:45:00
admin
原创
494
<!DOCTYPE html>
<html>
<head>
    <title>Client coordinates Example</title>
    <script type="text/javascript" src="http://code.ybao.org/demo/js/EventUtil.js"></script>
</head>
<body>
    <div id="myDiv" style="background-color:red;height:10000px;width:100px">Click me</div>
    <script>
        var div = document.getElementById("myDiv");
        EventUtil.addHandler(div, "click", function(event){
            event = EventUtil.getEvent(event);
            var pageX = event.pageX,
                pageY = event.pageY;
        
            if (pageX === undefined){
                pageX = event.clientX + (document.body.scrollLeft || document.documentElement.scrollLeft);
            }
        
            if (pageY === undefined){
                pageY = event.clientY + (document.body.scrollTop || document.documentElement.scrollTop);
            }
        
            alert("Page coordinates: " + event.pageX + "|" + pageX + "," + event.pageY + "|"+pageY);        
        });

    </script>
</body>
</html>
  • QQ讨论群
  • 关注微信
    • 欢迎咨询
    • 欢迎加入QQ群 16506021
  • 公众号:源宝网络