MouseEvent screenX Properti
Contoh
Dapatkan koordinat penunjuk tetikus, relatif terhadap layar, ketika tombol tetikus diklik pada suatu elemen:
var x = event.screenX; // Get the horizontal coordinate
var y = event.screenY; // Get the vertical coordinate
var coor = "X coords: " + x + ", Y coords: " + y;
Lebih banyak contoh "Coba Sendiri" di bawah ini.
Definisi dan Penggunaan
Properti screenX mengembalikan koordinat horizontal (menurut layar komputer pengguna) dari penunjuk tetikus ketika suatu peristiwa dipicu.
Tip: Untuk mendapatkan koordinat vertikal (menurut layar) dari penunjuk tetikus, gunakan properti screenY .
Catatan: Properti ini hanya-baca.
Dukungan Peramban
Property | |||||
---|---|---|---|---|---|
screenX | Yes | Yes | Yes | Yes | Yes |
Sintaksis
event.screenX
Detail Teknis
Nilai Kembali: | Angka, mewakili koordinat horizontal penunjuk tetikus, dalam piksel |
---|---|
Versi DOM: | Acara DOM Tingkat 2 |
Lebih Banyak Contoh
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 screenY Property
Referensi DOM HTML: MouseEvent clientX Property
Referensi HTML DOM: MouseEvent clientY Property
Referensi DOM HTML: MouseEvent offsetX Property
Referensi DOM HTML: MouseEvent offsetY Property