Remove the 300ms delay from phonegap apps

前端 未结 3 928
不思量自难忘°
不思量自难忘° 2020-12-24 14:55

I have been trying to make my app more responsive, but unfortunately nothing seems to help. I am using PhoneGap and hence I am experiencing the famous 300ms delay for touch

3条回答
  •  无人及你
    2020-12-24 15:06

    I solved it with a super minimal solution after some problems with fastclick when triggering click events. This example uses jQuery.

    $(document).on('touchstart', '.clickable', function(e){
        // This prevents the click to be completed
        // so will prevent the annoying flickering effect
        e.preventDefault();
    });
    

    You have to add .clickable class to any element you want to take out the 300m delay from.

    Then, change all click events for touchstart events, so this

    $('#elementid').click(function(e){
       console.log('ex event'); 
    }
    

    has to be now this

    $(document).on('touchstart', '#elementid', function(e){
       console.log('new event'); 
    }
    

提交回复
热议问题