From 52e9756b4aa5d22d5bae9d57e0191f3f04b51495 Mon Sep 17 00:00:00 2001 From: hwaphon Date: Tue, 26 Dec 2023 17:45:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(runtime-web):=20movable-view=20=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=9C=A8=E8=AE=BE=E7=BD=AE=E6=88=90=E4=BB=85=E6=B0=B4?= =?UTF-8?q?=E5=B9=B3=E6=96=B9=E5=90=91=E5=8F=AF=E6=BB=9A=E5=8A=A8=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=8F=96=E6=B6=88=E6=8E=89=E7=A6=81=E6=AD=A2=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E8=A1=8C=E4=B8=BA=E4=BB=A5=E6=94=AF=E6=8C=81=E7=BA=B5?= =?UTF-8?q?=E5=90=91=E6=BB=9A=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/src/views/movable-view.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/runtime-web/src/components/src/views/movable-view.ts b/packages/runtime-web/src/components/src/views/movable-view.ts index 609abc6f..752ca666 100644 --- a/packages/runtime-web/src/components/src/views/movable-view.ts +++ b/packages/runtime-web/src/components/src/views/movable-view.ts @@ -53,16 +53,21 @@ export default class MovableView extends BaseElement { this.updatePosition() } + preventDefault(event) { + if (this.direction !== 'horizontal') { + event.preventDefault() + } + } + onTouchStart = (e: TouchEvent) => { - // e.stopPropagation(); - e.preventDefault() + this.preventDefault(e) this.canMove = true } private canMove = false private lastPoint: { clientX; clientY } onMouseMove = (e: MouseEvent) => { - e.preventDefault() + this.preventDefault(e) if (e.buttons === 1) { // 只有鼠标左键处于按下状态才算 this.onMove({ clientX: e.clientX, clientY: e.clientY }) @@ -74,8 +79,7 @@ export default class MovableView extends BaseElement { } onTouchMove = (e: TouchEvent) => { - // e.stopPropagation(); - e.preventDefault() + this.preventDefault(e) const currentTouch = e.touches[0] this.onMove({ clientX: currentTouch.clientX,