[問題] 手動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