[问题] 手动touchevent

楼主: Allenbootung ($query)   2018-10-11 18:59:28
各位前辈好,我设备的讯号是TUIO,不是手机的触控,所以我需要自己产生touchevent
我输入两个点,但touchlist只会有一个点,移动还行,缩放就不行了,
请问要怎么把触控点加进去呢?
https://jsbin.com/zaxogifino/1/edit?js,console,output
myElement = document.querySelector('#g2');
sendTouchEvent(247, 379, myElement, 'touchstart');
sendTouchEvent(317, 591, myElement, 'touchstart');
sendTouchEvent(257, 389, myElement, 'touchmove');
sendTouchEvent(307, 581, myElement, 'touchmove');
sendTouchEvent(267, 399, myElement, 'touchmove');
sendTouchEvent(297, 571, myElement, 'touchmove');
以上缩放无效
function sendTouchEvent(x, y, element, eventType) {
const touchObj = new Touch({
identifier: Date.now(),
target: element,
clientX: x,
clientY: y,
pageX: x,
pageY: y,
screenX: x,
screenY: y,
radiusX: 25,
radiusY: 25,
rotationAngle: 0,
force: 0.5,
});
const touchEvent = new TouchEvent(eventType, {
cancelable: true,
bubbles: true,
touches: [touchObj],
targetTouches: [],
changedTouches: [touchObj],
shiftKey: true,
});
element.dispatchEvent(touchEvent);
}
作者: jhnny97 (≡(  ゚Д゚))   2018-10-12 03:07:00
https://codepen.io/HanMeow/pen/jzqMdW 之前测试touchevent用的,参考一下+用手机拉拉看,就大概知道要怎么写了

Links booklink

Contact Us: admin [ a t ] ucptt.com