Thuộc tính window.screenTop trả về tọa độ dọc của cửa sổ so với màn hình. Không hỗ trợ Firefox (dùng screenY thay thế).
Cú pháp
window.screenTop
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.screenTop (legacy)</h1>
<button onclick="showScreenTop()" class="btn">Xem screenTop</button>
<div class="show"></div>
<script>
function showScreenTop() {
var val = window.screenTop !== undefined ? window.screenTop : 'Không hỗ trợ (Firefox)';
document.querySelector('.show').innerHTML = 'screenTop: ' + val + 'px';
}
</script>
</body>
</html>
Kết quả
Trên Chrome/Edge/Safari: hiển thị số pixel. Trên Firefox: hiển thị "Không hỗ trợ".
Khuyến nghị: Luôn dùng window.screenY (hỗ trợ mọi trình duyệt) thay vì screenTop.