タッチイベントを処理する
const text = document.getElementById("text");
window.addEventListener("touchstart", (e) => {
const touchInfo = e.changedTouches;
console.log(touchInfo);
text.textContent = `タッチ開始:${touchInfo[0].pageX.toFixed(2)}`;
});
window.addEventListener("touchmove", () => {
text.textContent = "タッチ移動中";
});
window.addEventListener("touchend", () => {
text.textContent = "タッチ終了";
});マウスイベントと違い、タッチイベントは複数同時に発生する可能性がある。指2本の動作を検知するために event.changeTouchesを使ってタッチ情報にアクセスする