2011-09-23 111 views

回答

9

親愛的朋友們在你的HTML使用。它沒有運行,因爲在瀏覽器中工作的功能是根據鼠標運動模式。你所要做的事情是改變對移動然後正常工作觸控模式...

$(init); 

function init() { 
    document.addEventListener("touchstart", touchHandler, true); 
    document.addEventListener("touchmove", touchHandler, true); 
    document.addEventListener("touchend", touchHandler, true); 
    document.addEventListener("touchcancel", touchHandler, true); 
    } 
    function touchHandler(event) 
    { 
    var touches = event.changedTouches, 
    first = touches[0], 
    type = ""; 
    switch(event.type) 
    { 
    case "touchstart": type = "mousedown"; break; 
    case "touchmove": type="mousemove"; break;   
    case "touchend": type="mouseup"; break; 
    default: return; 
    } 
    var simulatedEvent = document.createEvent("MouseEvent"); 
    simulatedEvent.initMouseEvent(type, true, true, window, 1, 
         first.screenX, first.screenY, 
         first.clientX, first.clientY, false, 
         false, false, false, 0/*left*/, null); 
    first.target.dispatchEvent(simulatedEvent); 
    event.preventDefault(); 
    } 
+0

我只是這樣做的,但我解決了這個綁定touchstart和touchmove在一起,這很好:) –

+0

@阿米特哈夫你測試了這個在移動....? –

+0

@阿米特在我的暴徒它適用於拖放的工作正常,但問題是我可以拖動,但對於刪除我需要再次點擊,然後只有在移動,但瀏覽器下降工作正常... –