网页学习体会

  • 首页
  • 个人博客
您的位置: 首页  >  IT文章  >  C#  >  DOM中的有关问题,为什么新建的
层的坐标不是鼠标的位置,求高手解释

DOM中的有关问题,为什么新建的
层的坐标不是鼠标的位置,求高手解释

分类: IT文章 • 2024-11-10 07:57:31
DOM中的问题,为什么新建的<div>层的坐标不是鼠标的位置,求高手解释
<head>
    <title></title>
    <script type="text/javascript">
        function initEvent() {
            var as = document.getElementsByTagName("a");
            for (var i = 0; i < as.length; i++) {
                var a = as[i];
                a.onmouseover = aMouseOver;
            }
        }
        function aMouseOver() {
            //动态创建一个层;
            var div = document.createElement("div");
            div.style.position ="absolute";
            div.style.top = window.event.clientY;
            div.style.left = window.event.clientX;
            div.innerHTML = "测试";

            document.body.appendChild(div);//放到body中
        }
    </script>
</head>
<body onload="initEvent()">
<a href="http://www.baidu.com" >百度</a><br /><br />
<a href="http://www.baidu.com" >百度</a><br /><br />
<a href="http://www.baidu.com" >百度</a><br /><br />
</body>


为什么新建的<div>层的坐标不是鼠标的位置,求高手解释div.style.top = window.event.clientY;
            div.style.left = window.event.clientX;

------解决方案--------------------
Sets or retrieves the x-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars.


用screenX,screenY试试看吧

相关推荐

  • DOM中的有关问题,为什么新建的
    层的坐标不是鼠标的位置,求高手解释
  • 架构有关概念——学习笔记
  • 微服务~分布式事务里的终极一致性
    网站免责声明 网站地图 最新文章 用户隐私 版权申明
本站所有数据收集于网络,如果侵犯到您的权益,请联系网站进行下架处理。   

Copyright © 2018-2021   Powered By 网页学习体会    备案号:   粤ICP备20002247号