diff --git a/__tests__/snapshot/board/examples/test/event.html.jpg b/__tests__/snapshot/board/examples/test/event.html.jpg index 6c88d46..c390271 100644 Binary files a/__tests__/snapshot/board/examples/test/event.html.jpg and b/__tests__/snapshot/board/examples/test/event.html.jpg differ diff --git a/packages/board/examples/features/lib/event.js b/packages/board/examples/features/lib/event.js index 506cf60..15a8799 100644 --- a/packages/board/examples/features/lib/event.js +++ b/packages/board/examples/features/lib/event.js @@ -39,6 +39,6 @@ export function initEvent(board) { }) board.on('doubleClick', (p) => { - console.log('doubleClick', p); + console.log('on("doubleClick")', p); }) } \ No newline at end of file diff --git a/packages/board/examples/test/event.html b/packages/board/examples/test/event.html index 9153202..7f4be2e 100644 --- a/packages/board/examples/test/event.html +++ b/packages/board/examples/test/event.html @@ -109,7 +109,7 @@ \ No newline at end of file diff --git a/packages/board/src/lib/watcher.ts b/packages/board/src/lib/watcher.ts index 211e9f7..9a22033 100644 --- a/packages/board/src/lib/watcher.ts +++ b/packages/board/src/lib/watcher.ts @@ -101,12 +101,16 @@ export class Watcher { _listenClick(e: MouseEvent|TouchEvent) { e.preventDefault(); - const maxLimitTime = 300; + const maxLimitTime = 500; const p = this._getPosition(e); const t = Date.now(); if (this._isVaildPoint(p)) { const preClickPoint = this._temp.get('prevClickPoint'); - if (preClickPoint && t - preClickPoint.t <= maxLimitTime) { + if ( + preClickPoint && (t - preClickPoint.t <= maxLimitTime) + && Math.abs(preClickPoint.x - p.x) <= 5 + && Math.abs(preClickPoint.y - p.y) <= 5 + ) { if (this._event.has('doubleClick')) { this._event.trigger('doubleClick', { x: p.x, y: p.y }); } diff --git a/scripts/browser/event.js b/scripts/browser/event.js index 6b72e9f..435d7eb 100644 --- a/scripts/browser/event.js +++ b/scripts/browser/event.js @@ -1,3 +1,15 @@ +function click(opts){ + const { x,y } = opts; + const event = new MouseEvent('click', { + screenX: x, + screenY: y, + clientX: x, + clientY: y, + }); + const elem = document.elementFromPoint(x,y); + elem.dispatchEvent(event); +} + function mouseDown(opts){ const { x,y } = opts; const event = new MouseEvent('mousedown', { @@ -74,6 +86,7 @@ function wheelY(y, opts = { clientX: 0, clientY: 0 }){ export default { + click, mouseDown, mouseUp, mouseMove,