$("#category ul").find("li").each( function() {
$(this).mouseover( function() {
$(this).children("ul").show();
} );
$(this).mouseout( function() {
$(this).children("ul").hide();
} );
} );鼠标在下拉菜单移动时菜单会不断闪烁,说明不断触发了 mouseover 和 mouseout 事件。
其实很简单的解决方法:将 mouseover 改成 mouseenter,mouseout 改成 mouseleave。mouseenter 和 mouseleave 事件是 jQuery 库中实现的,并不是浏览器的原生事件。不过最重要的是把菜单不停闪动的问题解决了!
$("#category ul").find("li").each( function() {
$(this).mouseenter(function() {
$(this).children("ul").show();
} );
$(this).mouseleave(function() {
$(this).children("ul").hide();
} );
} );
Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务