Eliminate 300ms delay on click events in mobile Safari

后端 未结 10 2177
北恋
北恋 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:40

    Unfortunately there is no easy way to do this. So just using touchstart or touchend will leave you with other problems like someone starts scrolling when click on on a button for example. We use zepto for a while, and even with this really good framework there are some issues that came up over the time. A lot of them are closed, but it seems is not a field of simple solution.

    We have this solution to globally handle clicks on links:

       $(document.body).
        on('tap', 'a',function (e) {
          var href = this.getAttribute('href');
          if (e.defaultPrevented || !href) { return; }
          e.preventDefault();
          location.href= href;
        }).
        on('click', 'a', function (e) {
          e.preventDefault();
        });
    

提交回复
热议问题