From 28402d96b438a80cb0719ff1cb07abc39892589f Mon Sep 17 00:00:00 2001 From: dntzhang Date: Mon, 8 Apr 2019 17:49:11 +0800 Subject: [PATCH] cax-svg - event test --- packages/cax-svg/cax/svg/parse-event.js | 23 +++++++++++++++++++++++ packages/cax-svg/cax/svg/rect.js | 4 +++- packages/cax-svg/pages/index/index.js | 6 +++++- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 packages/cax-svg/cax/svg/parse-event.js diff --git a/packages/cax-svg/cax/svg/parse-event.js b/packages/cax-svg/cax/svg/parse-event.js new file mode 100644 index 000000000..fa7de4eb0 --- /dev/null +++ b/packages/cax-svg/cax/svg/parse-event.js @@ -0,0 +1,23 @@ +export function parseEvent(props, obj) { + const tapHandler = props.bindtap || props.bindTap || props.onTap || props.ontap || props.onclick || props.onClick || props.bindclick || props.bindClick + if (tapHandler) { + + let _x = null, + _y = null + + obj.on('touchstart', (evt) => { + _x = evt.stageX + _y = evt.stageY + }) + + obj.on('touchend', (evt) => { + if (_x !== null) { + console.log(Math.abs(evt.stageX - _x)) + console.log(Math.abs(evt.stageY - _y)) + if (Math.abs(evt.stageX - _x) < 20 && Math.abs(evt.stageY - _y) < 20) { + tapHandler(evt) + } + } + }) + } +} diff --git a/packages/cax-svg/cax/svg/rect.js b/packages/cax-svg/cax/svg/rect.js index 0f9812800..b1981322c 100644 --- a/packages/cax-svg/cax/svg/rect.js +++ b/packages/cax-svg/cax/svg/rect.js @@ -1,6 +1,7 @@ import Rect from '../render/display/shape/rect' import { parseStyle } from './parse-style' import { transform } from './parse-transform' +import { parseEvent } from './parse-event' export function rect(props) { @@ -16,7 +17,8 @@ export function rect(props) { rect.y = Number(options.y) transform(props, rect) - + parseEvent(props, rect) + return rect } \ No newline at end of file diff --git a/packages/cax-svg/pages/index/index.js b/packages/cax-svg/pages/index/index.js index e244c366d..0071719fa 100644 --- a/packages/cax-svg/pages/index/index.js +++ b/packages/cax-svg/pages/index/index.js @@ -7,9 +7,13 @@ Page({ + function tapHandler(){ + console.log('tapHandler') + } + const rect = new SVG(html` - `)