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` - `)