vuecssuiant-designantdreactantantd-vueenterprisefrontendui-designvue-antdvue-antd-uivue3vuecomponent
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.
33 lines
894 B
33 lines
894 B
import type { 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; |
|
}; |
|
};
|
|
|