From 141612a5198420b1c244c7116f953a25a98fe4a1 Mon Sep 17 00:00:00 2001 From: hymbz Date: Thu, 14 Dec 2023 21:46:28 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E8=A7=A6=E6=91=B8=E6=9D=BF=E8=BF=9B=E8=A1=8C=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E7=9A=84=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Manga/actions/operate.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/Manga/actions/operate.ts b/src/components/Manga/actions/operate.ts index 7a7f82c8..e8932bed 100644 --- a/src/components/Manga/actions/operate.ts +++ b/src/components/Manga/actions/operate.ts @@ -1,6 +1,6 @@ -import { debounce } from 'throttle-debounce'; +import { debounce, throttle } from 'throttle-debounce'; -import { getKeyboardCode } from 'helper'; +import { getKeyboardCode, isEqual } from 'helper'; import type { State } from '../store'; import { store, setState, refs, _setState } from '../store'; import { zoom } from './zoom'; @@ -151,6 +151,11 @@ const scrollModeScroll = (dir: 'next' | 'prev') => { closeScrollLock(); }; +let wheelDeltaY = 0; +const clearWheelDeltaY = debounce(1000, () => { + wheelDeltaY = 0; +}); + export const handleWheel = (e: WheelEvent) => { e.stopPropagation(); if (e.ctrlKey || e.altKey) e.preventDefault(); @@ -174,6 +179,11 @@ export const handleWheel = (e: WheelEvent) => { return zoom(store.zoom.scale + (isWheelDown ? -25 : 25), e); } + wheelDeltaY += e.deltaY; + clearWheelDeltaY(); + if (Math.abs(wheelDeltaY) < 40) return; + wheelDeltaY = 0; + return turnPage(isWheelDown ? 'next' : 'prev'); };