코딩 공부/JS
스크롤 이벤트 제어 방향알기, 스크롤 멈췄을때
hg_96
2023. 2. 8. 15:06
// 스크롤 멈춤 감지
$.fn.scrollStopped = function (callback) {
let _this = this, $this = $(_this);
$this.scroll(function(event) {
clearTimeout($this.data('scrollTimeout'));
$this.data('scrollTimeout', setTimeout(callback.bind(_this), 250, event));
});
};
addEventListener("scroll", e => {
$(window).scrollStopped(function (ev) {
// console.log("멈춤")
});
})
let lastScrollY = 0;
addEventListener("scroll", e => {
const scrollY = window.scrollY;
// 스크롤 올렸을때, 내렸을때
if (scrollY < lastScrollY) {
} else {
}
// 현재의 스크롤 값을 저장
lastScrollY = scrollY;
})