screenXイベント属性
イベントオブジェクト
定義と使い方
screenX イベント属性は、イベント発生時にマウスポインターがスクリーンに対して持つ水平座標を返します。
構文
event.screenX
例
例
次の例では、イベント発生時のマウスポインターの座標を表示します。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル(example.com)</title>
<script type="text/javascript">
function coordinates(event){
x=event.screenX
y=event.screenY
alert("X=" + x + " Y=" + y)
}
</script>
</head>
<body onmousedown="coordinates(event)">
<p>
ドキュメント内の任意の場所をクリックしてください。メッセージボックスに、スクリーンに対するポインターの x 座標と y 座標が表示されます。
</p>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル(example.com)</title>
<script type="text/javascript">
function coordinates(event){
x=event.screenX
y=event.screenY
alert("X=" + x + " Y=" + y)
}
</script>
</head>
<body onmousedown="coordinates(event)">
<p>
ドキュメント内の任意の場所をクリックしてください。メッセージボックスに、スクリーンに対するポインターの x 座標と y 座標が表示されます。
</p>
</body>
</html>
試してみる »
イベントオブジェクト その他の拡張