alexgibson / tap.js

DEPRECATED - A custom 'tap' event JavaScript plugin for touch devices
Other
349 stars 65 forks source link

Event Triggered Twice in Same Spot #18

Closed joshuabambrick closed 10 years ago

joshuabambrick commented 10 years ago

On Mobile Safari and Chrome for Mobile, I seem to find that the event fires a bit like a double click. The event fires as you would expect, however, immediately after this, it appears to detect another tap in exactly the same spot (although not necessarily the same element).

For example, I have a box with a 'show' button and a separate 'hide' button. When I click the 'show' button, it should stop being displayed and the 'hide' button should appear in its place - and vice versa. The events for these elements are added separately. However, when I tap the 'show' button, the 'hide' button appears before immediately swapping back.

alexgibson commented 10 years ago

Hard to say without testing, but I believe what is happening here is the default click event firing after the tap. In your tap event handler, try calling e.preventDefault();. This usually does the trick.

joshuabambrick commented 10 years ago

That does appear to fix the issue, thanks. Might it be worthwhile to consider building this in as an opt-out default? I'm not sure how likely others are to run into the same issue but I tried dropping tap.js into my app as a replacement for the click event and this seemed to happen on for every such event listener. Preventing this as the default would allow future users to avoid having to change every handler in their codebase.

That being said, I'm not sure how easy it would be to pass custom params when your defining a custom event - you'd be more experienced in the area than I would. Great plugin generally by the way.

alexgibson commented 10 years ago

Glad it worked, and thanks for the feedback. I'll consider it, but I think leaving it up to the author perhaps gives more control. This lib isn't really intended as a drop-in replacement for click events.