How to bind both Mousedown and Touchstart, but not respond to both? Android, JQuery

后端 未结 9 840
无人及你
无人及你 2020-12-04 14:24

Working on a website that is also viewable on mobile and need to bind an action on both touchstart and mousedown.

Looks like this

 $(\"#roll\").bind         


        
9条回答
  •  独厮守ぢ
    2020-12-04 15:07

    This native solution worked best for me:

    1. Add a touchstart event to the document settings a global touch = true.
    2. In the mousedown/touchstart handler, prevent all mousedown events when a touch screen is detected: if (touch && e.type === 'mousedown') return;

提交回复
热议问题