2011-01-27 43 views
1

我正在使用JavaScript事件(完全屬於我的一個主題),並且需要處理移動Safari中觸摸事件的一些指導。觸摸事件中的定位元素(移動探險)

我有一個文件,看起來像:

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

我想強調任何跨度用戶當前感人。

我已經成功地去

回答

1

的發揮我制定的解決方案是將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); 
    } 
}