使用mousemove方法时,怎么获取移动前和移动后的坐标。但移动前的坐标不要设置为0啊!求解!急急急急!!谢谢!

解决方案 »

  1.   

    使用mousemove方法时,怎么获取鼠标移动前和移动后的坐标。
      

  2.   

        <script type="text/javascript">
            function moveT(e){
              e=e||window.event;
              var x = e.clientX;
              var y = e.clientY;
              //alert(x+"="+y)
            }
        </script><body onmousemove="moveT(event)">
      

  3.   

    用body的mousemove事件抓取鼠标 位置每次触发事件都吧鼠标坐标追加到一个数组中
    那么这个 数组就是 鼠标轨迹路径至于 移动前 移动后 这个只是相对概念
    你自己要定义 整个鼠标路径数组中 那次算是开始
      

  4.   

    好像应该用 e.offsetX 而不是e.clientX
      

  5.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head><body>
    <p id="pos">&nbsp;</p><script type="text/javascript">
    var arrPos = new Array();
    window.onload = function() {
    document.getElementsByTagName('body')[0].onmousemove = function(e) {
    var x = e.clientX, y = e.clientY;
    arrPos.push(Array(x,y));
    document.getElementById('pos').innerHTML = 'X:<span>'+x+'</span>&nbsp;<span>Y:'+y+'</span>';
    }
    }
    </script>
    </body>
    </html>