【发布时间】:2016-03-30 19:11:31
【问题描述】:
我正在使用 jQuery Mobile 允许触摸屏用户通过向左滑动和向右滑动手势在网站中来回导航。问题是 swipeleft 和 swiperight 事件也是用普通鼠标触发的,这很烦人,因为它发生在用户用鼠标选择一些文本时。
您可以在网站本身 (http://laetitia-stucki.ch/) 和下面的 JavaScript sn-p 上看到问题。
您知道如何仅使用触摸设备而不是普通鼠标触发滑动事件吗?
"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;
}
})();
});
【问题讨论】:
-
滑动事件适用于鼠标移动和触摸手势。您需要先识别设备,然后仅对触摸屏应用滑动事件。检查此主题的主题:stackoverflow.com/questions/3514784/…
标签: jquery-mobile touch