jQuery Mobileを使用して、タッチスクリーンユーザーは、スワイプした右ジェスチャーでWebサイトを前後にナビゲートできます。問題は、swipeleftイベントとswiperightイベントも通常のマウスでトリガされ、ユーザがマウスでテキストを選択したときに発生するため、非常に面倒です。jQueryタッチスクリーンのみのためのモバイルスワイプジェスチャー
この問題は、Webサイト自体(http://laetitia-stucki.ch/)と以下のJavaScriptスニペットで確認できます。
通常のマウスではなく、タッチデバイスでのみスワイプイベントをトリガーする方法はありますか?
"use strict";
$(document).ready(function() {
(function() {
$("body").on("swiperight", function(e) { navigate_prev_page(); });
$("body").on("swipeleft", function(e) { navigate_next_page(); });
function navigate_next_page() {
var target_page = $(".button-next").first().attr("href");
window.location.href = target_page;
}
function navigate_prev_page() {
var target_page = $(".button-prev").first().attr("href");
window.location.href = target_page;
}
})();
});
スワイプイベントは、マウスの動きとタッチジェスチャで機能します。最初にデバイスを特定し、タッチスクリーンにのみスワイプイベントを適用する必要があります。このトレッドを確認してください:http://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device-in-jquery –