티스토리 뷰

공부

[JS] Browser get scroll direction

seunggabi 승가비 2019. 12. 22. 00:13
728x90
var lastScrollTop = 0;
$(window).scroll(function(event){
   var st = $(this).scrollTop() || window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;

출처: https://seunggabi.tistory.com/entry/JS-Browser-scrollTop [배우기를 멈추는 사람은 20세건 80세건 늙은 것이다.]
   if (st > lastScrollTop){
       // downscroll code
   } else {
      // upscroll code
   }
   lastScrollTop = st;
});

[출처] https://stackoverflow.com/questions/4326845/how-can-i-determine-the-direction-of-a-jquery-scroll-event

728x90

'공부' 카테고리의 다른 글

[SQL] Count by condition  (0) 2019.12.22
[JS] VueJS bind scroll event  (0) 2019.12.22
[JS] Browser get scroll direction  (0) 2019.12.22
[Git] How do I get the commit count?  (0) 2019.12.22
[Spring] Memory leak fixed!  (0) 2019.12.22
[JS] Browser & Screen size  (0) 2019.12.21
댓글
댓글쓰기 폼