MouseEvent clientY Properti
Contoh
Keluarkan koordinat penunjuk tetikus ketika tombol tetikus diklik pada suatu elemen:
var x = event.clientX; // Get the horizontal coordinate
var y = event.clientY; // Get the vertical coordinate
var coor = "X coords: " + x + ", Y coords: " + y;
Hasil coor dapat berupa:
X coords: 142, Y coords: 99
Lebih banyak contoh "Coba Sendiri" di bawah ini.
Definisi dan Penggunaan
Properti clientY mengembalikan koordinat vertikal (menurut area klien) dari penunjuk tetikus ketika peristiwa tetikus dipicu.
Area klien adalah jendela saat ini.
Tip: Untuk mendapatkan koordinat horizontal (sesuai dengan area klien) dari penunjuk tetikus, gunakan properti clientX .
Catatan: Properti ini hanya-baca.
Dukungan Peramban
Property | |||||
---|---|---|---|---|---|
clientY | Yes | Yes | Yes | Yes | Yes |
Sintaksis
event.clientY
Detail Teknis
Nilai Kembali: | Angka, mewakili koordinat vertikal penunjuk tetikus, dalam piksel |
---|---|
Versi DOM: | Acara DOM Tingkat 2 |
Lebih Banyak Contoh
Contoh
Keluarkan koordinat penunjuk tetikus saat penunjuk tetikus bergerak di atas suatu elemen:
var x = event.clientX;
var y = event.clientY;
var coor = "X coords: " + x + ", Y coords: " + y;
document.getElementById("demo").innerHTML = coor;
Contoh
Demonstrasi perbedaan antara clientX dan clientY dan screenX dan screenY:
var cX = event.clientX;
var sX = event.screenX;
var cY = event.clientY;
var sY = event.screenY;
var coords1 = "client - X: " + cX + ", Y coords: " + cY;
var coords2 = "screen - X: " + sX + ", Y coords: " + sY;
Halaman Terkait
Referensi DOM HTML: MouseEvent clientX Property
Referensi HTML DOM: MouseEvent screenX Property
Referensi DOM HTML: MouseEvent screenY Property
Referensi DOM HTML: MouseEvent offsetX Property
Referensi DOM HTML: MouseEvent offsetY Property