jQuery日本語リファレンス

jQuery does not mean Japanese Query...

Events/API/jQuery - Sample Code

mousemove(fn)


            
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="/jquery/js/jquery.js"></script>
  
  <script>
  $(document).ready(function(){
    
    $("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>
  <style>
  div { width:100px; height:170px; margin;10px; margin-right:50px;
        background:yellow; border:2px groove; float:right; }
  p { margin:0; margin-left:10px; color:red; width:250px;
      height:120px; padding-top:70px;
      float:left; font-size:14px; }
  span { display:block; }
  </style>
</head>
<body>
  <p>   
    Try scrolling too.
    <span>Move the mouse over the div.</span>

    <span> </span>
  </p>
  <div></div>
</body>
</html>
            
          
[実行結果]
[mousemove(fn) の説明へ]