Thuộc tính window.pageYOffset trả về số pixel tài liệu đã cuộn theo chiều dọc (từ góc trên bên trái).
Ví dụ
<!DOCTYPE html>
<html>
<head>
<style>
div { background-color: green; height: 1500px; width: 1500px; }
</style>
</head>
<body>
<script>
function scrollFunc() {
window.scrollBy(200, 200);
alert("Vertical: " + window.pageYOffset);
}
</script>
<button onclick="scrollFunc()" style="position:fixed;">Scroll</button>
<br><br><br>
<div></div>
</body>
</html>