iPad hover/click issue

為{幸葍}努か 提交于 2019-12-11 17:44:03

问题


I have my HTML code as;

<a href="someTarget.html" class="menuLink">Link</a>

Now the JS code previously was;

$(".menuLink").mouseover(function(){
    //code for show() submenu
}


$(".menuLink").mouseout(function(){
    //code for hide() submenu
}

I am testing this on iPad and the above code worked fine on the iPad (i.e. on first tap, it fires the hover event and shows the submenu and only on the next tap does it fire the click event or go to the target link)

For some reason (adding delay to the main menu), I had to update the code as follows;

$this.hover(
    function(){ // over
        $this.data("timer", setTimeout(show, 500));
    },
    function(){ // out
        $this.data("timer", setTimeout(hide, 500));
    }
)

So the Issue is as follows; On the first tap of the link, it immediately takes the user to the target URL (instead of 2 taps earlier for hover/click)

Please help me fix this issue.


回答1:


jQuery documentation says that $(selector).hover(handlerIn, handlerOut) is just a shortcut for using $(selector).mouseenter(handlerIn).mouseleave(handlerOut).

That means there is no mouseover()/mouseout() event binded to the object and maybe the mobile browser doesn't handle it correctly for the other 2 events (that is mouseenter()/mouseleave()).

Try replacing your code to this:

$this.mouseover(function(){ // over
        $this.data("timer", setTimeout(show, 500));
    }).mouseout(function(){ // out
        $this.data("timer", setTimeout(hide, 500));
    }
)

Let me know if that does the trick.




回答2:


Mobile devices does not support mouse hover event and also does not support double click event



来源:https://stackoverflow.com/questions/10978288/ipad-hover-click-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!