js_fake_touch
2021-06-03 18:05
标签:com pat ORC let ott dispatch cancel compose document js_fake_touch 标签:com pat ORC let ott dispatch cancel compose document 原文地址:https://www.cnblogs.com/daihanlong/p/12348362.html let ele = document.getElementById('GameCanvas');
let rect = ele.getBoundingClientRect();
let touch = new Touch({
"identifier" : 0,
"target" : ele,
"clientX" : (rect.left + rect.right)/2,
"clientY" : (rect.top + rect.bottom)/2,
"screenX" : (rect.left + rect.right)/2,
"screenY" : (rect.top + rect.bottom)/2,
"pageX" : (rect.left + rect.right)/2,
"pageY" : (rect.top + rect.bottom)/2,
"radiusX" : 11.5,
"radiusY" : 11.5,
"rotationAngle" : 0.0,
"force" : 1});
let touchstart = new TouchEvent("touchstart", {
cancelable: true,
bubbles: true,
composed: true,
touches: [touch],
targetTouches: [touch],
changedTouches: [touch]
});
let touchend = new TouchEvent("touchend", {
cancelable: true,
bubbles: true,
composed: true,
touches: [touch],
targetTouches: [touch],
changedTouches: [touch]
});
ele.dispatchEvent(touchstart);
ele.dispatchEvent(touchend);