manually trigger touch event

前端 未结 5 1050
甜味超标
甜味超标 2020-12-05 02:55

I searched for the past 30 minutes, but didn\'t find a solution.

I want to trigger a touchstart event on an element.

This fires the touchs

5条回答
  •  死守一世寂寞
    2020-12-05 03:15

    I know this has been answered, but I too struggled to find an answer to this problem and the accepted answer didn't work for me. In the end, the solution I found is really very simple and has support across browsers:

    var e = new Event('touchstart');
    target.dispatchEvent(e);
    

    That's it. Couldn't be easier.

提交回复
热议问题