Can I record mouse movements?

I would like to record mouse movements and clicks.

Can I do this using jQuery or another JS library?

thank

+3
source share
2 answers

take a look at: http://api.jquery.com/mousemove

there is a working example:

<!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>
+2
source

You can handle mousemovedocument event and track e.pageXand e.pageY.

0
source

All Articles