Thuộc tính window.screenY trả về tọa độ dọc (vertical) của cửa sổ trình duyệt so với màn hình (screen). Hỗ trợ tất cả trình duyệt hiện đại.
Cú pháp
window.screenY
Ví dụ
<!DOCTYPE html>
<html>
<style>
body { color: #000; height: 100vh; background-color: #8BC6EC; background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%); text-align: center; }
.btn { background: #db133a; border: none; height: 2rem; border-radius: 2px; width: 40%; display: block; color: #fff; outline: none; cursor: pointer; margin: 1rem auto; }
.show { font-size: 1.2rem; }
</style>
<body>
<h1>Demo window.screenY</h1>
<button onclick="showScreenY()" class="btn">Xem tọa độ Y màn hình</button>
<div class="show"></div>
<script>
function showScreenY() {
document.querySelector('.show').innerHTML = 'Tọa độ dọc cửa sổ so với màn hình: ' + window.screenY + 'px';
}
</script>
</body>
</html>
Kết quả
Nhấn nút → hiển thị khoảng cách từ cạnh trên màn hình đến cửa sổ trình duyệt (pixel).
Cặp đôi: screenX (tọa độ ngang). screenLeft/screenTop là alias cũ (IE), không hỗ trợ Firefox. Dùng screenX/Y cho cross-browser.