javascript - 在 jQuery Mobile 中检测从边缘滑动

标签 javascript jquery jquery-mobile mobile touch

在使用 $("#panel").panel("open"); 打开面板之前,我想检测用户是否从边缘滑动。这是代码

$("#main").on("swiperight",function(event){
var data = event.originalEvent.touches ? event.originalEvent.touches[0] : event,
    coords = [data.pageX, data.pageY];

console.log(coords);
});

但是 coords 没有返回任何东西,因为我得到了错误:

Uncaught TypeError: Cannot read property 'touches' of undefined

  1. 那么滑动发生时有没有办法获取坐标?

  2. 或者有没有一种简单的方法可以检测凝视位置是否来自 改为左边缘?

谢谢。

最佳答案

在 jqm 1.4+ 中尝试以下,对我有用,相应地调整边缘 trim 值,50 对我来说很好

$( "div.ui-page" ).on( "swiperight", function( e ) {
    if ( e.swipestart.coords[0] <50) {
    // your logic 
    }
});

这是 x 坐标,同样你可以从 coords[1] 得到 y

关于javascript - 在 jQuery Mobile 中检测从边缘滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20109508/

相关文章:

javascript - React Redux - 更改未反射(reflect)在组件中

javascript - 如何为具有相似值的动态表格行设置不同的背景颜色?

javascript - 如何在此代码中从 "on click"更改为鼠标悬停时

jquery - 如何在拨动开关下方放置一条水平线

javascript - 无法让 $(window).load() 在加载到 div 的页面上工作

javascript - .findOne 在 Iron Router Route 的数据属性中工作,但 .find 不工作?

javascript - 为什么此代码在不同值下表现不同

javascript - 如何 jQuery - 添加按钮插入最多 10 个新输入

javascript - 如何自定义(或禁用)JQueryMobile 中的自动 "back"按钮

javascript - 动态插入的 JQuery Mobile slider