반응형
document.addEventListener('scroll', () => {
const currentScrollPercentage = getCurrentScrollPercentage();
// ㅠㅠ 10% 단위로 어케쏘지하다가 숫자앞자리 10 20 30 이면 1,2,3 요렇게 빼서 바뀌면 쏘게했다.
prev_percent[count++] = currentScrollPercentage ;
let pre = String(prev_percent[count-2] ?prev_percent[count-2] :currentScrollPercentage) ;
if(pre != currentScrollPercentage){
if(pre.substr(0,1) != String(currentScrollPercentage).substr(0,1)){
sendScroll(currentScrollPercentage);
}
}
});
})
/* 스크롤 퍼센테이지 return */
function getCurrentScrollPercentage(){
return (window.scrollY + window.innerHeight) / document.body.clientHeight * 100
}반응형
'자바스크립트' 카테고리의 다른 글
| 앵귤러 프로미스 ,$q 사용법 (0) | 2022.03.29 |
|---|---|
| 자바스크립트 리스트 sort 정렬 (0) | 2021.06.09 |
| 자바스크립트 속성추가 ,속성변경,속성삭제 (0) | 2021.01.14 |
| 자바스크립트 1월 12월 날짜 (0) | 2021.01.05 |
| 자바스크립트 한달 전 (0) | 2020.12.31 |
댓글