スマートフォン, タブレットなどタッチイベントを検出します。
window.addEventListener('load', (event) => {
let e: HTMLElement | null = document.querySelector('#canvas-wrapper canvas');
["touchstart", "touchmove", "touchend"].forEach((type: any) => {
if (!e) return;
e.addEventListener(type, (event: TouchEvent) => {
event.preventDefault();
let e: HTMLElement | null = document.querySelector('#info');
let s: string = '';
if(!e) return;
e.innerHTML = '';
for (var i = 0; i < event.touches.length; i++) {
var t = event.touches[i];
s += "[" + i + "]";
s += "x=" + t.pageX + ",";
s += "y=" + t.pageY + "<br>";
}
e.innerHTML = s;
}, { passive: false });
})
})