From 78944bf441f94bf3299ce0d91c154d8346d0d335 Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 17 Jul 2023 09:50:34 +0000 Subject: [PATCH] :v: --- .../frontend/src/components/MkPagination.vue | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/packages/frontend/src/components/MkPagination.vue b/packages/frontend/src/components/MkPagination.vue index 89f358c8c..924db25d0 100644 --- a/packages/frontend/src/components/MkPagination.vue +++ b/packages/frontend/src/components/MkPagination.vue @@ -233,43 +233,23 @@ watch([$$(weakBacked), $$(contentEl)], () => { })(); }); -function preventDefault(ev: Event) { - ev.preventDefault(); -} - /** * アイテムを上に追加した場合に追加分だけスクロールを下にずらす * @param fn DOM操作(unshiftItemsなどで) */ function adjustScroll(fn: () => void): Promise { const oldHeight = scrollableElement ? scrollableElement.scrollHeight : getBodyScrollHeight(); - const oldScroll = scrollableElement ? scrollableElement.scrollTop : window.scrollY; - // スクロールをやめさせる - try { - // なぜかscrollableElementOrHtmlがundefinedであるというエラーが出る - scrollableElementOrHtml.addEventListener('mousewheel', preventDefault, { passive: false }); - scrollableElementOrHtml.addEventListener('touchmove', preventDefault, { passive: false }); - // ついでにtryに入れてみる - scroll(scrollableElement, { top: oldScroll, behavior: 'instant' }); - } catch (err) { - console.error(err, { scrollableElementOrHtml }); - } denyMoveTransition.value = true; fn(); return nextTick(() => { - try { - const top = oldScroll + ((scrollableElement ? scrollableElement.scrollHeight : getBodyScrollHeight()) - oldHeight); - scroll(scrollableElement, { top, behavior: 'instant' }); + const diff = (scrollableElement ? scrollableElement.scrollHeight : getBodyScrollHeight()) - oldHeight; + const newScroll = scrollableElement ? scrollableElement.scrollTop : window.scrollY; + const top = newScroll + diff; + scroll(scrollableElement, { top, behavior: 'instant' }); - // なぜかscrollableElementOrHtmlがundefinedであるというエラーが出る - scrollableElementOrHtml.removeEventListener('mousewheel', preventDefault); - scrollableElementOrHtml.removeEventListener('touchmove', preventDefault); - } catch (err) { - console.error(err, { scrollableElementOrHtml }); - } denyMoveTransition.value = false; return nextTick(); });