2021-06-26 01:35:40 +00:00
|
|
|
import type { Ref } from 'vue';
|
2020-10-01 09:20:10 +00:00
|
|
|
|
|
|
|
export default (isScrollAtTop: Ref<boolean>, isScrollAtBottom: Ref<boolean>) => {
|
2020-09-28 11:14:00 +00:00
|
|
|
// Do lock for a wheel when scrolling
|
|
|
|
let lock = false;
|
2020-10-01 09:20:10 +00:00
|
|
|
let lockTimeout: any = null;
|
2020-09-28 11:14:00 +00:00
|
|
|
function lockScroll() {
|
|
|
|
clearTimeout(lockTimeout);
|
|
|
|
|
|
|
|
lock = true;
|
|
|
|
|
|
|
|
lockTimeout = setTimeout(() => {
|
|
|
|
lock = false;
|
|
|
|
}, 50);
|
|
|
|
}
|
2020-10-01 09:20:10 +00:00
|
|
|
return (deltaY: number, smoothOffset = false) => {
|
2020-09-28 11:14:00 +00:00
|
|
|
const originScroll =
|
|
|
|
// Pass origin wheel when on the top
|
2020-09-29 07:16:56 +00:00
|
|
|
(deltaY < 0 && isScrollAtTop.value) ||
|
2020-09-28 11:14:00 +00:00
|
|
|
// Pass origin wheel when on the bottom
|
2020-09-29 07:16:56 +00:00
|
|
|
(deltaY > 0 && isScrollAtBottom.value);
|
2020-09-28 11:14:00 +00:00
|
|
|
|
|
|
|
if (smoothOffset && originScroll) {
|
|
|
|
// No need lock anymore when it's smooth offset from touchMove interval
|
|
|
|
clearTimeout(lockTimeout);
|
|
|
|
lock = false;
|
|
|
|
} else if (!originScroll || lock) {
|
|
|
|
lockScroll();
|
|
|
|
}
|
|
|
|
|
|
|
|
return !lock && originScroll;
|
|
|
|
};
|
|
|
|
};
|