Eliminate 300ms delay on click events in mobile Safari

后端 未结 10 2153
北恋
北恋 2020-11-28 18:34

I\'ve read that mobile Safari has a 300ms delay on click events from the time the link/button is clicked to the time the event fires. The reason for the delay is to wait to

10条回答
  •  执念已碎
    2020-11-28 18:46

    i know this is old but can't you just test to see if "touch" is supported in the browser? Then create a variable that's either "touchend" or "click" and use that variable as the event that gets bound to your element?

    var clickOrTouch = (('ontouchend' in window)) ? 'touchend' : 'click';
    $('#element').on(clickOrTouch, function() {
        // do something
    });
    

    So that code sample checks to see if the "touchend" event is supported in the browser and if not then we use the "click" event.

    (Edit: changed "touchend" to "ontouchend")

提交回复
热议问题