1

タッチハンドラーについて少し質問があります...タッチで動作する場合があり、描画後にデータを読み取ることができず、直線で描画されるため、どのような問題があり、何が間違っていたのでしょうか? 私を助けてください..私はすでに自分のコードをjsfiddleに入れています..私を助けてください(http://jsfiddle.net/Frebu/1/)

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 init(id) {
        document.getElementById(id).addEventListener("touchstart", touchHandler, true);
        document.getElementById(id).addEventListener("touchmove", touchHandler, true);
        document.getElementById(id).addEventListener("touchend", touchHandler, true);
    }
$(document).ready(function() {
        init('myCanvas');
});​
4

1 に答える 1

1

私のお勧めは、hammer.js を使用することです。これは優れたタッチ ライブラリです (ブラウザーでマウスにフォールバックします)。

http://eightmedia.github.com/hammer.js/

それを除けば、タッチイベントをシミュレートするChromeでフィドルをテストしても問題はありませんでした。奇妙なことに、コードは問題ないようです。

于 2012-06-25T03:47:10.190 に答える