parent
c4f8cda4aa
commit
7e06a6a2b7
|
@ -39,6 +39,7 @@ const isPullEnd = ref(false);
|
|||
const isRefreshing = ref(false);
|
||||
const pullDistance = ref(0);
|
||||
|
||||
let supportPointerDesktop = false;
|
||||
let startScreenY: number | null = null;
|
||||
|
||||
const rootEl = useTemplateRef('rootEl');
|
||||
|
@ -57,11 +58,10 @@ const emit = defineEmits<{
|
|||
}>();
|
||||
|
||||
function getScreenY(event) {
|
||||
if (event.touches && event.touches[0] && event.touches[0].screenY != null) {
|
||||
event.touches[0].screenY;
|
||||
} else {
|
||||
if (supportPointerDesktop) {
|
||||
return event.screenY;
|
||||
}
|
||||
return event.touches[0].screenY;
|
||||
}
|
||||
|
||||
function moveStart(event) {
|
||||
|
@ -129,7 +129,7 @@ function moveEnd() {
|
|||
function moving(event: TouchEvent | PointerEvent) {
|
||||
if (!isPullStart.value || isRefreshing.value || disabled) return;
|
||||
|
||||
if ((scrollEl?.scrollTop ?? 0) > SCROLL_STOP + pullDistance.value || isHorizontalSwipeSwiping.value) {
|
||||
if ((scrollEl?.scrollTop ?? 0) > (supportPointerDesktop ? SCROLL_STOP : SCROLL_STOP + pullDistance.value) || isHorizontalSwipeSwiping.value) {
|
||||
pullDistance.value = 0;
|
||||
isPullEnd.value = false;
|
||||
moveEnd();
|
||||
|
@ -186,18 +186,14 @@ function onScrollContainerScroll() {
|
|||
|
||||
function registerEventListenersForReadyToPull() {
|
||||
if (rootEl.value == null) return;
|
||||
rootEl.value.addEventListener('mousedown', moveStart, { passive: true });
|
||||
rootEl.value.addEventListener('touchstart', moveStart, { passive: true });
|
||||
rootEl.value.addEventListener('touchmove', moving, { passive: false }); // passive: falseにしないとpreventDefaultが使えない
|
||||
window.addEventListener('pointermove', moving, { passive: true });
|
||||
}
|
||||
|
||||
function unregisterEventListenersForReadyToPull() {
|
||||
if (rootEl.value == null) return;
|
||||
rootEl.value.removeEventListener('mousedown', moveStart);
|
||||
rootEl.value.removeEventListener('touchstart', moveStart);
|
||||
rootEl.value.removeEventListener('touchmove', moving);
|
||||
window.removeEventListener('pointermove', moving);
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
@ -209,7 +205,6 @@ onMounted(() => {
|
|||
scrollEl.addEventListener('scroll', onScrollContainerScroll, { passive: true });
|
||||
|
||||
rootEl.value.addEventListener('touchend', moveEnd, { passive: true });
|
||||
window.addEventListener('pointerup', moveEnd, { passive: true });
|
||||
|
||||
registerEventListenersForReadyToPull();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue