mousePositionTracker.html 860 Bytes
Newer Older
Kriengkrai Yothee's avatar
Kriengkrai Yothee committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
<html>
  <head>
    <style type="text/css">
      div.solidborder
      {
        border-style:solid;
        border-width:1px;
      }
    </style>

  <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
  <script type="text/javascript" src="js/jquery-ui-1.8.10.custom.min.js"></script>
  <script type="text/javascript">
    jQuery(document).ready(function(){
        $('#mousetracker').mousemove(function(e){
          xPos = e.pageX - this.offsetLeft;
          yPos = e.pageY - this.offsetTop;
          $('#status').html(xPos + ', ' + yPos);
          });
        })

</script>
<body>
  <b>Div tracking mouse position.</b>
  <br>
<div id="mousetracker" class="solidborder" style="position: absolute; left: 10px; top: 80px; height: 400px; width: 100px; padding: 0px;">
  Move mouse here.
</div>
<h2 id="status">
0, 0
</h2>
</body>
</html>