Source Code: (back to article)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Scroll Position Detector</title>
</head>
<body>
<div style="height: 3000px;">
<div style="position: fixed;">Scroll position: <span id="position">0</span>px</div>
</div>
<script>
const positionSpan = document.getElementById('position');
window.addEventListener('scroll', function() {
positionSpan.innerHTML = window.pageYOffset;
});
</script>
</body>
</html>