MouseEvent: clientY-Eigenschaft

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Die clientY-Schreibgeschützte Eigenschaft des MouseEvent-Interfaces bietet die vertikale Koordinate innerhalb des Viewports der Anwendung, an der das Ereignis aufgetreten ist (im Gegensatz zur Koordinate innerhalb der Seite).

Zum Beispiel wird ein Klick auf den oberen Rand des Viewports immer ein Mausereignis mit einem clientY-Wert von 0 ergeben, unabhängig davon, ob die Seite vertikal gescrollt ist oder nicht.

Wert

Ein double-Gleitkommawert in Pixeln.

Beispiele

Dieses Beispiel zeigt die Koordinaten Ihrer Maus an, wann immer Sie das mousemove-Ereignis auslösen.

HTML

html
<p>Move your mouse to see its position.</p>
<p id="screen-log"></p>

JavaScript

js
let screenLog = document.querySelector("#screen-log");
document.addEventListener("mousemove", logKey);

function logKey(e) {
  screenLog.innerText = `
    Screen X/Y: ${e.screenX}, ${e.screenY}
    Client X/Y: ${e.clientX}, ${e.clientY}`;
}

Ergebnis

Spezifikationen

Specification
UI Events
# dom-mouseevent-clienty

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
clientY

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Siehe auch