【发布时间】:2015-05-17 23:31:31
【问题描述】:
在我的 jquery 移动应用程序中,我有来自他们网站的代码,用于检测滑动以使用滑动打开面板。这是代码:
function swipePanel(pageId, leftPanelId) {
$( document ).on( "pageinit", pageId, function() {
$( document ).on( "swipeleft swiperight", pageId, function( e ) {
// We check if there is no open panel on the page because otherwise
// a swipe to close the left panel would also open the right panel (and v.v.).
// We do this by checking the data that the framework stores on the page element (panel: open).
if ( $.mobile.activePage.jqmData( "panel" ) !== "open" ) {
if ( e.type === "swiperight" ) {
$( leftPanelId ).panel( "open" );
}
}
});
});
}
我删除了一点(向左滑动检测,因为我只需要向右滑动)。
问题是,如果我从任何地方向右滑动,例如如果我的手指超过屏幕 x 轴的 75%,并且我向右滑动,就会触发此代码。我想要这样,如果我向右滑动,并且我的手指从屏幕 x 轴的
有人知道怎么做吗?
谢谢
【问题讨论】:
-
为什么不将事件仅绑定到您希望滑动发生的最顶层元素?或者创建一个空的 div,占据屏幕的所需部分来捕捉事件。
-
您也可以查看
e.pageX/ window.innerWidth,并且仅在超过 x% 时才这样做
标签: javascript jquery html jquery-mobile swipe