window.scrollY
뷰포트 최상단에서부터 현재 스크롤까지의 거리를 구하고 이용하기
// 현재 스크롤까지의 거리를 정수로 구하기
const currentY = Math.round(window.scrollY);
function scrollEvent() {
// 현재 스크롤이 n 과 같거나 클 경우
if (currentY >= n) {
doSomething();
} else {
doNothing();
}
}
// 스크롤 이벤트가 발생 때마다 scrollEvent 실행하기
document.addEventListener("scroll", scrollEvent);