悬停意图不起作用

发布于 2024-10-03 07:57:40 字数 871 浏览 0 评论 0原文

我多次重新检查我的代码,并在另一个正在运行的网站上使用类似的东西。 这是该网站的链接: http://bit.ly/34XhDb

    //add hover intent to dropdown
jQuery(document).ready(function(){
var config = {
sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
interval: 100, // number = milliseconds for onMouseOver polling interval
over: doOpen, // function = onMouseOver callback (REQUIRED)
timeout: 1200, // number = milliseconds delay before onMouseOut
out: doClose // function = onMouseOut callback (REQUIRED)
};

function doOpen() {
    jQuery(this).addClass("hover");
    jQuery('ul:first',this).fadeIn();
}
function doClose() {
    jQuery(this).removeClass("hover");
    jQuery('ul:first',this).fadeOut();
}
jQuery("ul#main_catnav li").hoverIntent(config);

});

我用调试检查过,但似乎没有冲突,加上正在应用悬停类别。

谢谢你!

I recheck my code many times and I use something similar on another website where it is working.
Here is the link to the site:
http://bit.ly/34XhDb

    //add hover intent to dropdown
jQuery(document).ready(function(){
var config = {
sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
interval: 100, // number = milliseconds for onMouseOver polling interval
over: doOpen, // function = onMouseOver callback (REQUIRED)
timeout: 1200, // number = milliseconds delay before onMouseOut
out: doClose // function = onMouseOut callback (REQUIRED)
};

function doOpen() {
    jQuery(this).addClass("hover");
    jQuery('ul:first',this).fadeIn();
}
function doClose() {
    jQuery(this).removeClass("hover");
    jQuery('ul:first',this).fadeOut();
}
jQuery("ul#main_catnav li").hoverIntent(config);

});

I checked with debug but does not appear to be a conflict, plus the class of hover is being applied.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瞎闹 2024-10-10 07:57:40

问题不在于插件,而在于你的CSS,你有这样的:

ul#main_catnav ul { /*...other styles... */ display: none; }
ul#main_catnav li:hover ul { display: block}

所以当鼠标离开时, :hover 不再被应用,它会立即被CSS而不是JavaScript隐藏。要使其正常工作,您还需要添加 li.hover ,如下所示:

ul#main_catnav ul { /*...other styles... */ display: none; }
ul#main_catnav li:hover ul, ul#main_catnav li.hover ul { display: block}

这说明元素要么被鼠标悬停,要么具有类 .hover ,例如您可以使用 hoverIntent 插件来提供它。

The problem isn't the plugin, it's your CSS, you have this:

ul#main_catnav ul { /*...other styles... */ display: none; }
ul#main_catnav li:hover ul { display: block}

So when the mouse leaves that :hover isn't being applied anymore and it's hidden instantly by CSS, not JavaScript. To get it working you need to add li.hover as well, like this:

ul#main_catnav ul { /*...other styles... */ display: none; }
ul#main_catnav li:hover ul, ul#main_catnav li.hover ul { display: block}

Which accounts for the element either being hovered by the mouse, or having the class .hover like you're giving it with the hoverIntent plugin.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文