0

私はこのようなコードを使用して、ipad/iphone で、html Web ページにある (そしてうまく機能する) jQuery UI スライダー & ドラッグ % ドロップに反応するようにしています。

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 ボタン (「input」や「a」など) を単純にクリック (タップ) したい場合に機能しないことです。

「このタップを最初のタッチのように理解して動く」みたいな感じだと思います。同じ場所を(移動またはドラッグせずに)単純にタップすると、どうすればそれも機能しますか。または、HTML の特定の要素に触れた場合。

本当にありがとう、ライオネル

4

1 に答える 1

2

私も同じ問題に直面しました。しかし、touch.js ファイルを次のように少し変更することでこれを修正できます。

于 2012-08-07T04:41:46.210 に答える