在jQuery Mobile中检测从边缘滑动

时间:2013-11-20 23:40:43

标签: 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没有返回任何内容,因为我收到了错误:

  

未捕获的TypeError:无法读取未定义的属性'touches'

  1. 有什么方法可以在滑动时获得坐标?

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

  3. 感谢。

3 个答案:

答案 0 :(得分:4)

在jqm 1.4+中尝试以下,为我工作,相应地调整边缘修剪值,50对我有好处

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

这对于x坐标同样可以从coords [1]

得到y

答案 1 :(得分:3)

这适用于任何屏幕尺寸:

baseurl = string.Format(baseurl, recipientMobileNumber, HttpUtility.UrlEncode(message));

答案 2 :(得分:0)

你可以这样做。

$('#main').on('touchstart', function(e) {
   var xPos = e.originalEvent.touches[0].pageX;
   if(xPos == 0) { //Keep in mind the margin of failure from 0, when user touches.
      //Handle edge swipe
   }
});
相关问题