You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/vc-virtual-list/hooks/useOriginScroll.ts

34 lines
889 B

import { Ref } from 'vue';
export default (isScrollAtTop: Ref<boolean>, isScrollAtBottom: Ref<boolean>) => {
// Do lock for a wheel when scrolling
let lock = false;
let lockTimeout: any = null;
function lockScroll() {
clearTimeout(lockTimeout);
lock = true;
lockTimeout = setTimeout(() => {
lock = false;
}, 50);
}
return (deltaY: number, smoothOffset = false) => {
const originScroll =
// Pass origin wheel when on the top
(deltaY < 0 && isScrollAtTop.value) ||
// Pass origin wheel when on the bottom
(deltaY > 0 && isScrollAtBottom.value);
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;
};
};