我可以录制鼠标移动吗?

时间:2011-03-13 15:08:11

标签: javascript jquery

我想录制鼠标移动和点击。

我可以使用JQuery或其他JS库吗?

谢谢

2 个答案:

答案 0 :(得分:2)

看看:http://api.jquery.com/mousemove

有一个有效的例子:

<!DOCTYPE html>
<html>
<head>
  <style>
  div { width:220px; height:170px; margin;10px; margin-right:50px;
        background:yellow; border:2px groove; float:right; }
  p { margin:0; margin-left:10px; color:red; width:220px;
      height:120px; padding-top:70px;
      float:left; font-size:14px; }
  span { display:block; }
  </style>
  <script src="http://code.jquery.com/jquery-1.5.js"></script>
</head>
<body>
  <p>   
    Try scrolling too.
    <span>Move the mouse over the div.</span>
    <span>&nbsp;</span>
  </p>

  <div></div>
<script>
    $("div").mousemove(function(e){
      var pageCoords = "( " + e.pageX + ", " + e.pageY + " )";
      var clientCoords = "( " + e.clientX + ", " + e.clientY + " )";
      $("span:first").text("( e.pageX, e.pageY ) - " + pageCoords);
      $("span:last").text("( e.clientX, e.clientY ) - " + clientCoords);
    });

</script>

</body>
</html>

答案 1 :(得分:0)

您可以处理文档的mousemove事件并跟踪e.pageXe.pageY