diff --git a/uni_modules/cool-ui/components/cl-banner/cl-banner.uvue b/uni_modules/cool-ui/components/cl-banner/cl-banner.uvue index 64fb560..acf86e7 100644 --- a/uni_modules/cool-ui/components/cl-banner/cl-banner.uvue +++ b/uni_modules/cool-ui/components/cl-banner/cl-banner.uvue @@ -12,11 +12,9 @@ > Math.abs(y)) { + // 如果x轴移动距离大于y轴移动距离则表明是横向移动手势 + touchHorizontal = 1 + } + if (touchHorizontal == 1) { + // 如果是横向移动手势,则阻止默认行为(防止页面滚动) + e.preventDefault() + } + } + + // 横向移动时才处理 + if (touchHorizontal != 1) { + return + } + // 计算手指移动距离,实时更新偏移量 const deltaX = e.touches[0].clientX - touchStartPoint.value; slideOffset.value = initialOffset.value + deltaX; @@ -347,6 +372,9 @@ function onTouchMove(e: TouchEvent) { */ function onTouchEnd() { if (props.list.length <= 1 || !isTouching.value) return; + + touchStartY = 0; + touchHorizontal = 0; // 重置触摸状态 isTouching.value = false; @@ -409,6 +437,13 @@ onMounted(() => { getRect(); startAutoplay(); }); + +// 将触摸事件暴露给父组件,支持控制其它view将做touch代理 +defineExpose({ + onTouchStart, + onTouchMove, + onTouchEnd, +});