Javascript on iOS: Avoid click events by scrolling iPhone/iPad

Asked

Viewed 446 times

3

Setting:

I have a table and on the Desktop I must keep double click to access the content of each table item. On mobile devices like tablet and smart phone Double click does not work and I need to implement just one click/touch.

Code:

Checks if it’s a mobile device and keeps it by default if it’s not a double click. If you are a mobile device, use the touchend event to click. The problem is that it is not working on iPhone/iPad, when giving scroll it already triggers the event of click. Works only on Android devices.

Any suggestions?

var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);
var clickEvent = 'dblclick';

if(isMobile) {
    clickEvent = 'touchend click';
}

$(document).on(clickEvent, '.class', function() {

/* faz alguma coisa */

});
  • Tested only the 'click' instead of 'touchend click'; ?

  • @Jorgecampos Yes, I tested and it didn’t work

2 answers

3


I made a functional example in jsFiddle, also put comments that help understand logic . http://jsfiddle.net/M4gQG/1/

Remembering that on the desktop works with double click and on mobile devices in general, works with one touch, it also allows scrolling on the touchscreen.

  • This example is working perfectly for my need Juan! Thank you so much for your help!

1

Implementing touch with touchend is very simplistic, because you will get cases like scroll and any other touch.

Best to use some event implementation tap. If you use Zepto, you have on('tap',...). Or use the Tappy (https://github.com/filamentgroup/tappy) or Hammerjs or Fastclick or ... etc.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.