简体   繁体   English

iPad悬停事件jQuery

[英]Ipad hover event jQuery

Im trying to create a false hover event for my site using jQuery... 我正在尝试使用jQuery为我的网站创建错误的悬停事件...

I have created the following only all the child elements in my list now return false also as opposed to linking to the correct page... 我只创建了以下列表中的所有子元素,现在也返回false,而不是链接到正确的页面...

if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
    $("ul.sf-menu li.i").click(function(e) {
        e.preventDefault();
    });
}

Has anybody an idea on an alternative method that could work? 有人对可行的替代方法有任何想法吗?


HTML 的HTML

<ul class="sf-menu"> <li><a href="index.html">Home</a><li class="i"><a href="wedding-hire.html">Weddings</a>
            <ul>
                <li><a href="peel-suite.html">Peel Suite</a></li>
                <li><a href="the-hall.html">The Hall</a></li>
                <li><a href="the-grounds.html">The Grounds</a></li>
                <li><a href="food-and-drink.html">Food &amp; Drink</a></li>
                <li><a href="pricing.html">Pricing</a></li>
            </ul>
        </li>

well. 好。 without HTML its kind of hard to tell. 没有HTML,很难说。 But you are stopping the default behavior of the browser when the user clicks on the li (and therefor also its children, which I suppose is an anchor/link). 但是,当用户单击li时,您将停止浏览器的默认行为(因此也将终止其子级,我认为这是锚/链接)。 you could check if its a link or an anchor on click and handle it differently; 您可以检查它是否是链接或点击锚点,并以不同的方式处理它;

$("ul.sf-menu li.i").click(function(e) {
    if (e.target.nodeName!=="A"){
        e.preventDefault();
        //do your hover code
    }
    else{
        //do nothing, because the user wants the link to load
    }
});

更改您的选择器,使其仅与列表点的第一级匹配,我也看不到类,因此您可能还需要从选择器中删除该类。

$("ul.sf-menu > li") 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM