screenYイベント属性
イベントオブジェクト
定義と使用法
screenY イベント属性は、イベント発生時にマウスポインタの画面に対する垂直座標を返します。
構文
event.screenY
例
例
次の例は、イベント発生時のマウスポインタの座標を表示します。
<!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>
試してみる »
イベントオブジェクト その他の拡張