【问题标题】:How do I avoid hover event to fire in iPhone and iPad?如何避免在 iPhone 和 iPad 中触发悬停事件?
【发布时间】:2015-06-19 07:35:22
【问题描述】:

假设这些事件不会在 iOS 设备上触发,我在 Div 上添加了对 hoverEnter 和 hoverLeave 的效果。但是在 iOS 设备上,hoverEnter 和 click 事件会触发,并且会保持 hoverEnter 效果。我不希望这些悬停事件在移动设备上触发。我该怎么办。我正在通过 Javascript 附加事件,并且悬停事件在单击事件之前附加到 div。

【问题讨论】:

    标签: javascript ios jquery-events jquery-hover


    【解决方案1】:

    要模拟悬停,您只需将事件侦听器添加到要具有悬停事件的元素,您可以使用 touchstart 和 touchend 事件而不是使用悬停

    if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
        $(".menu li a").bind('touchstart', function(){
            console.log("touch started");
        });
        $(".menu li a").bind('touchend', function(){
            console.log("touch ended");
        });
    }
    

    【讨论】:

    • 我不想模拟悬停事件。它也只能在触摸(单击)时使用 hoverEnter 来触发。因此,即使单击完成,hoverEnter 的 css 样式也会保持不变,因为 hoverLeave 永远不会触发。
    • 这就是我想解释的,如果您签出example,它将帮助您解决问题
    猜你喜欢
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-17
    • 2010-12-21
    • 2013-07-12
    相关资源
    最近更新 更多