触摸事件

您所在的位置:网站首页 笔记本触摸板两个手指滑动屏幕 触摸事件

触摸事件

2023-11-12 12:58| 来源: 网络整理| 查看: 265

当页面加载时,下文的 startup() 函数由 window.onload 属性触发。

js

window.onload = function startup() { const el = document.getElementsByTagName("canvas")[0]; el.addEventListener("touchstart", handleStart, false); el.addEventListener("touchend", handleEnd, false); el.addEventListener("touchmove", handleMove, false); log("初始化成功。"); };

该函数为 元素设置了所有相关的事件监听器,使事件在触发时能够得到处理。

跟踪新触摸

我们将跟踪当前存在的所有触摸点。

js

const ongoingTouches = [];

当 touchstart 事件触发时,平面上即出现一个新的触摸点,继而调用 handleStart() :

js

function handleStart(evt) { evt.preventDefault(); console.log("触摸开始。"); const el = document.getElementsByTagName("canvas")[0]; const ctx = el.getContext("2d"); const touches = evt.changedTouches; for (let i = 0; i


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3