页面坐标位置

2017-06-19 11:45:00
admin
原创
319
<!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>
文章分类
联系我们
电话: 18902328227
Email: 2689701946@qq.com
QQ: 2689701946
微信: 18902328227
地址: 广州番禺区繁华路
  • 在线客服
  • 关注微信
  • 联系电话
    • 欢迎咨询
    • 欢迎加入QQ群 303257430
  • 公众号:源宝网络
    • 联系电话及微信号 18902328227