简体   繁体   中英

How can I tell the difference between click events and swipe events in JavaScript?

I am using OnsenUI 2 with ReactJS for developing a Cross-Platform App with Cordova. It should run on mobile devices, but it would be nice if it works on normal browsers too. I have a Carousel Element with full screen images and when the user taps on the image I want to open a new page. The problem is, that every swipe to a new image is triggering a click event on the image. How can I tell the difference between a tap on the slide and a swipe to the new slide?

Codepen: https://codepen.io/anon/pen/amJooZ

If you're developing something for a touch screen, instead of listening for click events, you should listen for touch events. See MDN's documentation of touch events . If it's important to handle normal click events as well, see the section about handling clicks .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM