Detect Scroll Direction ? #346
Answered
by
idiotWu
sadeghbarati
asked this question in
Q&A
Replies: 4 comments
-
let lastOffset = null;
scrollbar.addListener(({ offset }) => {
if (!lastOffset) {
lastOffset = offset;
return;
}
const dir = [];
if (offset.y < lastOffset.y) {
dir[0] = 'up';
} else if (offset.y > lastOffset.y) {
dir[0] = 'down';
} else {
dir[0] = 'still';
}
if (offset.x < lastOffset.x) {
dir[1] = 'left';
} else if (offset.x > lastOffset.x) {
dir[1] = 'right';
} else {
dir[1] = 'still';
}
lastOffset = offset;
switch(dir[0]) {
case 'up':
case 'down':
case 'still':
}
switch(dir[1]) {
case 'left':
case 'right':
case 'still':
}
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
idiotWu
-
Why did you remove the |
Beta Was this translation helpful? Give feedback.
0 replies
-
@anuragsr because it's not necessary in most cases. |
Beta Was this translation helpful? Give feedback.
0 replies
-
@idiotWu Ok I guess you have your reasons. Nice library btw! I just feel that the scroll direction is a pretty handy property to have, many uses for animations :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
when use smooth-scrollbar how to detect scroll direction from a fixed element ?
Beta Was this translation helpful? Give feedback.
All reactions