jQuery mobile- For every live tap event should there be an equivalent click event?

后端 未结 5 1168
Happy的楠姐
Happy的楠姐 2020-11-30 22:18

I have replaced the jQuery live click events to jQuery mobile tap events to increase responsiveness.

I have a feeling this was a bad idea for compatibility reasons.<

5条回答
  •  星月不相逢
    2020-11-30 22:32

    You can bind multiple events in one call like this:

    $('selector').bind('click tap',function(){ ... })
    

    This might be fine in some browsers/mobiles, however, this might make the events fire twice on some devices who trigger both the tap and click.

    You can fix this by doing some kind of device/feature detection and adding the appropriate handler only like this...

    $('selector').bind( myCustomDetectionFunction() ? 'click' : 'tap' ,function(){ ... })
    

    Additionally, I think touchstart and mousedown are better events to choose. This is because, after a touch, the click event does not fire until a delay has passed, as the system is allowing the chance for a second touch to make it a double click or for it to become a swipe gesture and so on. The touchstart event fires immediately, as does mousedown so should be more responsive.

提交回复
热议问题