Why onclick event suppressed, when preventDefault() is called for the touchstart event?

后端 未结 2 799
星月不相逢
星月不相逢 2021-01-06 14:27

I try to implement some javascript functions for my Ipad device. I would like to use some swipe action and click action on my canvas div.

I implemented the horizonta

相关标签:
2条回答
  • 2021-01-06 14:51

    I know Prusse has already answered this question correctly, but it lacks the confidence I search for in an answer. The reason the click event suppressed by preventDefault() in touchstart is because any event connected and following touchstart will be suppressed. The solution is to add preventDefault() to the touchmove event instead.

    This is explained in more detail in the Mozilla documentation under Handling Clicks:

    Since calling preventDefault() on a touchstart or the first touchmove event of a series prevents the corresponding mouse events from firing, it's common to call preventDefault() on touchmove rather than touchstart. That way, mouse events can still fire and things like links will continue to work.

    0 讨论(0)
  • 2021-01-06 14:53

    You could try to prevent the default action of the touchmove event.

    0 讨论(0)
提交回复
热议问题