0
<html>
<head>
<style>

    div{
        border: 1px solid black;
        width: 500px;
        height: 500px;      
    } 
    </style>
    <script>
    window.onload = function(){

        document.body.onmousedown = function(event){

           var mouseStartX = event.clientX;
           var mouseStartY = event.clientY;


            document.body.onmousemove = function(event){

                 var div = document.getElementsByTagName("div");
                 div[0].innerHTML = event.clientX + " " + event.clientY;


            }

        };

   };
</script>
</head>
<body>
<div>
</div>
</body>
</html>

这是我的代码,我只希望我的鼠标光标位置仅在我同时触发 onmousedown 和 onmousemove 事件时触发,这意味着我在鼠标周围单击并拖动。

4

1 回答 1

0

还有其他用于拖动的事件,请尝试使用:

document.ondragstart = function (e) {console.log(e)}

这将输出:

drag MouseEvent {dataTransfer: Clipboard, toElement: a, fromElement: null, y: 98, x: 177…}
于 2013-07-04T15:29:58.683 回答