JQuery mobile swipe event on Android emulator work

2019-09-16 18:57发布

问题:

I added swipeleft and swiperight listeners this way

$("#slides li").swipeleft(function(){
    console.log("!!!! swipe left");
});
$("#slides li").swiperight(function(){      
    console.log("!!!! swipe right");            
});

And it works sometimes, but mostly not. I'm not doing anything different.

I'm using PhoneGap 1.4.0, JQuery mobile 1.0 and JQuery min 1.7.1.

Any ideas...? Thanks in advance.

回答1:

Mobile browsers generally have problems with the id attribute, due to how their caching works. This means that the id attribute isn't always unique even though you only use it once on your page.

You can try to bind your swipe events to a class instead so you avoid those kinds of problems. It may look something like this:

$('.slides').bind('swiperight',function(event, info){
    console.log("!!!! swipe right"); 
});

jQuery Mobile also have some constants in the javascript code that defines how sensitive it should be to different gestures (such as swipe). You may want to change these constants to make your application more sensitive to swipe-events.