我正在处理 Javascript 事件(一个对我来说完全陌生的主题),并且需要一些关于在移动 Safari 中处理触摸事件的指导。
我有一个类似于以下内容的文档:
<div>
<span>one</span><span>two</span>
</div>
我想突出显示用户当前正在触摸的任何范围。
我已经成功了
最佳答案
我找到的解决方案是将事件监听器添加到文档中:
document.addEventListener("touchstart", touchStart, "true");
document.addEventListener("touchmove", touchMove, "true");
document.addEventListener("touchend", touchEnd, "true");
然后对每个触摸事件执行您需要的操作。我对此加注星号是因为它不是具有位置的事件本身(就像在正常事件处理中一样),而是具有位置的一组触摸。
function touchMove(event)
{
// // Prevent the webview itself from scrolling / bouncing around
event.preventDefault();
// Only track one finger
if ( event.touches.length == 1)
{
var touch = event.touches[0];
doStuffAtPosition(touch.pageX, touch.pageY);
}
}
关于javascript - 定位触摸事件中的元素(mobile safari),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4812078/