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

后端 未结 26 1758
太阳男子
太阳男子 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:40

    cduruk's solution was quite effective, but caused problems on a few parts of my site. Because I was already using jQuery to add the CSS hover class, the easiest solution was to simply not add the CSS hover class on mobile devices (or more precisely, to ONLY add it when NOT on a mobile device).

    Here was the general idea:

    var device = navigator.userAgent.toLowerCase();
    var ios = device.match(/(iphone|ipod|ipad)/);
    
    if (!(ios)) {
        $(".portfolio-style").hover(
            function(){
                $(this).stop().animate({opacity: 1}, 100);
                $(this).addClass("portfolio-red-text");
            },
            function(){
                $(this).stop().animate({opacity: 0.85}, 100);
                $(this).removeClass("portfolio-red-text");
            }
        );
    }
    

    *code reduced for illustrative purposes

提交回复
热议问题