admin管理员组

文章数量:1429153

There is a lot of material/posts on ghost clicks and I'm trying to understand it better. So the way I understand it, the reason for ghost clicks is the click event being dispatched ~300ms after the touch event. jQuery Mobile suggests to not use their vclick event whenever there is any chance of changing the content underneath the finger position.

My first question would be: Does that mean ghost clicks will only fire if the element targeted by click is different from the one originally touched? So, say, I write a database entry when a button is touched – nothing else. Is there a chance of ghost clicking or not?

If this is the case, wouldn't that mean that I can prevent ghost clicks altogether if I simply use only tap events and no click events whatsoever?

My last question would be if I can simply tell the browser to not use the 300ms delay when using PhoneGap (which would instantly solve the problem), but I'd just guess that I can't do that as it's probably hard-coded into the browser.

There is a lot of material/posts on ghost clicks and I'm trying to understand it better. So the way I understand it, the reason for ghost clicks is the click event being dispatched ~300ms after the touch event. jQuery Mobile suggests to not use their vclick event whenever there is any chance of changing the content underneath the finger position.

My first question would be: Does that mean ghost clicks will only fire if the element targeted by click is different from the one originally touched? So, say, I write a database entry when a button is touched – nothing else. Is there a chance of ghost clicking or not?

If this is the case, wouldn't that mean that I can prevent ghost clicks altogether if I simply use only tap events and no click events whatsoever?

My last question would be if I can simply tell the browser to not use the 300ms delay when using PhoneGap (which would instantly solve the problem), but I'd just guess that I can't do that as it's probably hard-coded into the browser.

Share Improve this question asked Nov 4, 2012 at 13:38 Ingo BürkIngo Bürk 20.1k7 gold badges70 silver badges103 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

The click event is delayed by 300 ms to detect things like double tap or fat finger mistakes.

Yes, wherever possible you should use the touch events instead.

Yes, there are many ways to enable fast clicks by doing a bit of JS. For instance:

  1. https://developers.google./mobile/articles/fast_buttons
  2. https://forum.jquery./topic/how-to-remove-the-300ms-delay-when-clicking-on-a-link-in-jquery-mobile
  3. http://labs.ft./2011/08/fastclick-native-like-tapping-for-touch-apps/

You don't have to live with the 300ms delay.

If everything on your page that can be clicked has the appropriate vclick jQuery event handlers installed, then one easy way of stopping ghost clicks is create a touchend event handler on the body and call preventDefault from it:

$(document.body).on('touchend', null, function(e) {
  e.preventDefault();
});

Note that this will disable regular clicks from touches, so any conventional links or form inputs you have will stop working unless you add vclick handlers to them.

本文标签: javascriptGhostclicks in mobile appsStack Overflow