mod: 调整多标签滑动写法

This commit is contained in:
张传龙 2022-05-01 18:16:41 +08:00
parent 894b87426a
commit 76bd414941

View File

@ -47,6 +47,8 @@ const contextMenuOption = reactive({
currentPath: '', currentPath: '',
}) })
let translateX = ref(0) let translateX = ref(0)
const tagsContent = ref()
const tagsWrapper = ref()
watch( watch(
() => route.path, () => route.path,
@ -82,33 +84,33 @@ async function handleContextMenu(e, tagItem) {
showContextMenu() showContextMenu()
} }
const tagsContent = ref()
const tagsWrapper = ref()
function handleMouseWheel(e) { function handleMouseWheel(e) {
let { wheelDelta } = e let { wheelDelta } = e
const tagsWrapperWidth = tagsWrapper.value.offsetWidth const tagsWrapperWidth = tagsWrapper.value.offsetWidth
const tagsContentWidth = tagsContent.value.offsetWidth const tagsContentWidth = tagsContent.value.offsetWidth
/** /**
* @wheelDelta >0 向左滑动 <0: 向右滑动 * @wheelDelta 平行滚动的值 >0 右移 <0: 左移
* @translateX 内容translateX的值
* @tagsWrapperWidth 容器的宽度
* @tagsContentWidth 内容的宽度
*/ */
//
//
if (wheelDelta > 0 && translateX.value >= 0) { if (wheelDelta > 0 && translateX.value >= 0) {
return return
} }
// + // +
if (wheelDelta < 0 && tagsWrapperWidth > tagsContentWidth + translateX.value) { if (wheelDelta < 0 && tagsWrapperWidth > tagsContentWidth + translateX.value) {
return return
} }
if (wheelDelta > 0 && wheelDelta + translateX.value > 0) { if (wheelDelta > 0 && wheelDelta + translateX.value > 0) {
translateX.value = 0 wheelDelta = -translateX.value
return
} }
if (wheelDelta < 0 && -wheelDelta > tagsWrapperWidth - (tagsContentWidth + translateX.value)) { if (wheelDelta < 0 && -wheelDelta > tagsWrapperWidth - (tagsContentWidth + translateX.value)) {
wheelDelta = -(tagsContentWidth + translateX.value - tagsWrapperWidth) wheelDelta = tagsWrapperWidth - (tagsContentWidth + translateX.value)
} }
translateX.value += wheelDelta translateX.value += wheelDelta