0

ユーザーがページ要素を左にスワイプしているときにキャプチャし、スワイプが行われている間に関数を実行することはできますか? 多少の解決策はありますが、ページを下にスクロールしているときに、要素を指で少し左にスワイプすると、関数が実行されます。

私の現在の解決策:

function touchMove() {
    finalCoord.x = event.targetTouches[0].pageX;
    changeX = originalCoord.x - finalCoord.x;
    var changeY = originalCoord.y - finalCoord.y;
    if (changeY < threshold.y && changeY > (threshold.y * -1)) {
        changeX = originalCoord.x - finalCoord.x;
        if (changeX > threshold.x) {
            $(document).off("touchmove", ".row");
            if ($(event.target).attr("class") === "row-inside") {
                var element = $(event.target);
            }
            if ($(event.target).attr("class") === "row-l") {
                var element = $(event.target).parent();
            }
            if ($(event.target).attr("class") === "row-r") {
                var element = $(event.target).parent();
            }
            setTimeout(function () {
                $(document).on("touchmove", ".row", function () {
                    touchMove();
                });
            }, 800);
        }
    }
}
function touchStart() {
    originalCoord.x = event.targetTouches[0].pageX;
    finalCoord.x = originalCoord.x;
}
$(document).on("touchmove", ".row", function () {
    touchMove();
});
$(document).on("touchstart", ".row", function () {
    touchStart();
});
}

jQuery モバイルを使おうと思ったのですが、swipeLeftイベントはスワイプ中ではなく、スワイプが終了したときにのみ発生します。

4

1 に答える 1

0

その用語はドラッグです。

私は多くの方法を試しましたが、最善の方法は Hammer.js を使用することです。

https://github.com/EightMedia/hammer.js/wiki/Getting-Started Hammer.jsの dragleft イベントを使用します。

ここでモバイルデバイスのいくつかの例を確認してください: http://eightmedia.github.io/hammer.js/examples/carousel.htmlドラッグレフトについては、カルーセルを試してください。

于 2013-08-12T23:13:15.707 に答える