iPad/iPhone hover problem causes the user to double click a link

后端 未结 26 1697
太阳男子
太阳男子 2020-11-27 09:18

I have some websites I built times ago, that use jquery mouse events...I just got an ipad and i noticed that all the mouse over events are translated in clicks...so for inst

26条回答
  •  失恋的感觉
    2020-11-27 09:33

    I am too late, I know but this is one of the easiest workaround I've found:

        $('body').on('touchstart','*',function(){   //listen to touch
            var jQueryElement=$(this);  
            var element = jQueryElement.get(0); // find tapped HTML element
            if(!element.click){
                var eventObj = document.createEvent('MouseEvents');
                eventObj.initEvent('click',true,true);
                element.dispatchEvent(eventObj);
            }
        });
    

    This does not only works for links(anchor tags) but for other elements also. Hope this helps.

提交回复
热议问题