Use onclick and ontouchstart

2

I have this div:

<div onclick="funcao('')">

And on Iphone (mainly the 6) the onclick does not run very well. I saw the ideal is to use the ontouchstart , but when I put both of the error, it thinks it was clicked twice.

What to do?

    
asked by anonymous 10.06.2016 / 17:47

1 answer

3

What I usually do is like this:

var appEvents = {
    down: 'ontouchstart' in window ? 'touchstart' : 'click' /* ou mousedown */,
    move: 'ontouchmove' in window ? 'touchmove' : 'mousemove',
    up: 'ontouchend' in window ? 'touchend' : 'mouseup'
    // e outros que precises
}

and then use

el.addEventListener(appEvents.down, function(){

so it detects if it is in a browser environment and uses click or mobile environment and uses touchstart

    
10.06.2016 / 18:06