fix(components): 修复多页签Tab自动滚动问题

This commit is contained in:
Soybean
2021-11-25 21:48:39 +08:00
parent 93f9aa9584
commit 20aa39f14e
3 changed files with 34 additions and 8 deletions

View File

@@ -32,7 +32,12 @@ const bsScroll = ref<ExposeBetterScroll | null>(null);
function handleScroll(clientX: number) {
const currentX = clientX - bsWrapperLeft.value;
const deltaX = currentX - bsWrapperWidth.value / 2;
bsWrapperRef.value?.scrollBy({ left: deltaX, behavior: 'smooth' });
if (bsScroll.value) {
const { maxScrollX, x: leftX } = bsScroll.value.bsInstance;
const rightX = maxScrollX - leftX;
const update = deltaX > 0 ? Math.max(-deltaX, rightX) : Math.min(-deltaX, -leftX);
bsScroll.value?.bsInstance.scrollBy(update, 0, 300);
}
}
function init() {