我正在与JavaScript活动(对我完全陌生)合作,需要在移动野生动物园中处理触摸事件的一些指导。

我有一个看起来像:

<div>
    <span>one</span><span>two</span>
</div>

我想突出显示用户当前触摸的任何跨度。

我已经成功去了

有帮助吗?

解决方案

我解决的解决方案是将EventListeners添加到文档:

    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);
    }
}

其他提示

您可能想结帐 http://www.jqtouch.com/

它创建了一个名为“ Tap”的事件 https://github.com/senchalabs/jqtouch/wiki/callbackevents

您可以在这里玩JQTouch的演示 http://www.jqtouch.com/preview/demos/main/#home

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top