2012-04-26 33 views
0

我正在使用這樣的代碼來使它響應一個jQuery UI滑塊&在ipad/iphone上拖放%的東西,這是在html網頁(並且很好地工作)。touch.js模擬jQuery在iphone上的拖拽

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

function initTouch() 
{ 
    document.addEventListener("touchstart", touchHandler, true); 
    document.addEventListener("touchmove", touchHandler, true); 
    document.addEventListener("touchend", touchHandler, true); 
    document.addEventListener("touchcancel", touchHandler, true);  
} 
$(document).ready(function(){initTouch();}); 

拖動和滑動效果很好。 問題是,當我想在一個html按鈕(如「輸入」或「一個」)上做一個簡單的點擊(點擊)不工作。

我認爲這就像「它理解這個水龍頭就像第一次觸摸移動」。 當我在同一個地方輕鬆點擊(沒有移動或拖動)時,我該怎麼辦,讓它也能起作用。或者如果我觸摸HTML的特定元素。

真的感謝, 梅西

+0

已解決http://touchpunch.furf.com/ – Lionel 2012-04-26 14:56:50

回答

2

我也面臨着同樣的問題。但能夠通過更改touch.js文件有點像這樣修復: 「if($(this).attr('href')=='')」event.preventDefault();