0

我正在使用这样的代码使其响应 jQuery UI 滑块和拖放内容,这些内容位于 ipad/iphone 上的 html 网页中(并且运行良好)。

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 按钮(如“输入”或“a”)上进行简单的单击(点击)时不起作用。

我认为这类似于“它像第一次触摸一样理解这个点击”。我该怎么做,当我在同一个地方简单地点击(不移动或拖动)时,让它也能工作。或者,如果我触摸 HTML 的特定元素。

非常感谢,莱昂内尔

4

1 回答 1

2

我也面临同样的问题。但是可以通过在 event.preventDefault() 之前更改 touch.js 文件来解决这个问题: "if($(this).attr('href')=='')";

于 2012-08-07T04:41:46.210 回答