如何在jQuery Mobile中检测滑动位置

时间:2012-12-22 08:17:59

标签: jquery jquery-mobile swipe

我正在构建一个jQuery Mobile应用程序,我需要一种在滑动事件期间跟踪用户手指移动的方法。我找到了jGestures,它似乎在swipemove事件中提供了这个功能,但我希望不必导入另一个库。 jQuery Mobile swipe事件是否会返回此类信息?

1 个答案:

答案 0 :(得分:6)

只能使用jQM。我为您创建了一个示例:http://jsfiddle.net/Gajotres/cnuGy/。我已在Windows Firefox,Android 4.1堆栈浏览器和iPad中测试过它。

$('#index').on('touchstart vmousedown', function(){
    $('#start').val('Touch start');
})

$('#index').on('touchmove vmousemove', function(event){
    $('#move-x').val(event.pageX);
    $('#move-y').val(event.pageY);
})

$('#index').on('touchend vmouseup', function(){
    $('#end').val('Touch end');
});

vmousedown等V事件仅适用于鼠标,而触摸事件适用于触摸设备(iPad,Android ......)。