스크롤 퍼센트

박진·2021년 4월 18일
0
const scroll = document.documentElement.scrollTop;
per = Math.ceil((scroll / (document.body.scrollHeight - window.outerHeight)) * 100);

scroll 라는 변수를 통해서 현재 스크롤의 값을 얻을수있다.
여기에 전체 스크롤 값(전체페이지 길이) 에서 전체 윈도우창, 즉 브라우저 사이드바 모두를 포함한 값을 빼주어 나온값을 스크롤로 나누면 된다.

profile
Hello :)

0개의 댓글