From 76bd4149416942d145d9c2765174019205378d35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E4=BC=A0=E9=BE=99?= Date: Sun, 1 May 2022 18:16:41 +0800 Subject: [PATCH] =?UTF-8?q?mod:=20=E8=B0=83=E6=95=B4=E5=A4=9A=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E6=BB=91=E5=8A=A8=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/components/tags/index.vue | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/layout/components/tags/index.vue b/src/layout/components/tags/index.vue index a8aa071..317cedd 100644 --- a/src/layout/components/tags/index.vue +++ b/src/layout/components/tags/index.vue @@ -47,6 +47,8 @@ const contextMenuOption = reactive({ currentPath: '', }) let translateX = ref(0) +const tagsContent = ref() +const tagsWrapper = ref() watch( () => route.path, @@ -82,33 +84,33 @@ async function handleContextMenu(e, tagItem) { showContextMenu() } -const tagsContent = ref() -const tagsWrapper = ref() - function handleMouseWheel(e) { let { wheelDelta } = e const tagsWrapperWidth = tagsWrapper.value.offsetWidth const tagsContentWidth = tagsContent.value.offsetWidth /** - * @wheelDelta >0: 向左滑动 <0: 向右滑动 + * @wheelDelta 平行滚动的值 >0: 右移 <0: 左移 + * @translateX 内容translateX的值 + * @tagsWrapperWidth 容器的宽度 + * @tagsContentWidth 内容的宽度 */ - // 向左滑动时,如果无偏移或者向左偏移,则不处理 + + // 向右移动时时,如果无偏移或者向左偏移,则不处理 if (wheelDelta > 0 && translateX.value >= 0) { return } - // 向右滑动,如果内容的宽度小于向左偏移的宽度+容器的宽度,则不处理 + // 向左移动时,如果内容的宽度小于向左偏移的宽度+容器的宽度,则不处理 if (wheelDelta < 0 && tagsWrapperWidth > tagsContentWidth + translateX.value) { return } if (wheelDelta > 0 && wheelDelta + translateX.value > 0) { - translateX.value = 0 - return + wheelDelta = -translateX.value } if (wheelDelta < 0 && -wheelDelta > tagsWrapperWidth - (tagsContentWidth + translateX.value)) { - wheelDelta = -(tagsContentWidth + translateX.value - tagsWrapperWidth) + wheelDelta = tagsWrapperWidth - (tagsContentWidth + translateX.value) } translateX.value += wheelDelta