Phonegap 2.4.0 with Android 4.2 - strange double click behaviour

前端 未结 5 1064
暖寄归人
暖寄归人 2020-12-30 08:03

I\'m using phonegap 2.4.0 to create an Android and iOS App.

Now I recognized that the onclick event in links is fired twice inside the Android App using Android 4.2.

5条回答
  •  渐次进展
    2020-12-30 08:37

    I handled my similar situation very closely to Soulwax's solution, however I didn't want to hinder fast clicks by the user by keeping track of time intervals. Instead, I simply track the event type in the link's data object and if it's trying to handle a click immediately after a touchstart I ignore that call.

    $('.link').on('touchstart click', function(e){
      e.preventDefault();
    
      //Prevent against handling a click immediately after touchstart.
      if(e.type == "click" && $(this).data("lastTouch") == "touchstart"){
        e.stopImmediatePropagation();
        return false;
      }
      $(this).data("lastTouch", e.type);
    
      $('.nav-bar').toggleClass('active');
    });
    

提交回复
热议问题