@ムトゥ
これは、「ビューポートでマウスの X 座標と Y 座標を取得する」動作デモですhttp://jsfiddle.net/XsqBz/
そして、完全なソースの下を見つけてください。楽しみ。
<!doctype html>
<html lang="en">
<head>
<title>jQuery: Getting X and Y coordinates of the mouse in the viewport</title>
<style>
html{background:#f9f9f9;background-color:#f9f9f9;}
body{background:#fff;background-color:#fff;color:#666;font-family:"Lucida Grande",Verdana,Arial,Georgia,"Bitstream Vera Sans","Bitstream Charter",sans-serif,serif;margin:2em auto;width:700px;padding:1em 2em;-moz-border-radius:11px;-khtml-border-radius:11px;-webkit-border-radius:11px;border-radius:11px;border:1px solid #dfdfdf;}
body{
font-size:11px;
line-height:15px;
background:#fff;
background-color:#fff;
color:#666;
margin-left:20px;
}
strong{font-size:12px;}
a:link{color:#0066CC;}
a:hover{color:#FF6600;}
a:visited{color:#003366;}
a:active{color:#9DCC00;}
p{font-size:18px;}
.relativeX, .relativeY{color:#666;font-size:13pt;}
.relativeX{font-size:48pt;color:#fc0;position:relative;top:-20px;left:30px;}
.relativeY{font-size:52pt;position:relative;top:-09px;left:-10px;}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<!-- Move mouse over div to get position -->
<div style="margin:10px;height:400px;width:90%;min-width:420px;background:#ccc;padding:20px;border:1px dotted #777;display:block;">
relative to this
</div>
<script>
(function($) {
$(document).bind('contextmenu', function(){
return false;
});
$('div').mousemove(function(e){
// Relative to this div element instead of document
var relativeX = e.pageX - this.offsetLeft;
var relativeY = e.pageY - this.offsetTop;
$(this).html('releativeX = <span class="relativeX">' + relativeX + '</span>, releativeY = <span class="relativeY">' + relativeY + '</span>');
});
})(jQuery);
</script>
</body>
</html>