悬停意图不起作用
我多次重新检查我的代码,并在另一个正在运行的网站上使用类似的东西。 这是该网站的链接: 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题不在于插件,而在于你的CSS,你有这样的:
所以当鼠标离开时,
:hover
不再被应用,它会立即被CSS而不是JavaScript隐藏。要使其正常工作,您还需要添加 li.hover ,如下所示:这说明元素要么被鼠标悬停,要么具有类 .hover ,例如您可以使用
hoverIntent
插件来提供它。The problem isn't the plugin, it's your CSS, you have this:
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 addli.hover
as well, like this:Which accounts for the element either being hovered by the mouse, or having the class
.hover
like you're giving it with thehoverIntent
plugin.