Jquery 的菜单错误
我正在开发的菜单有一个错误,一切都很顺利,直到您将鼠标快速悬停在菜单的子菜单上。
该错误在 Firefox 和 Chrome 上也不同,我认为这是因为一个渲染速度比另一个更快,在 Firefox 中它成为一个无限错误,在 Chrome 中它持续几秒钟,然后消失。
这是我的 html 代码:
<div id="menu" class="ui-accordion-header ui-helper-reset ui-state-default ui-corner-all">
<label class="formatText" id="lblIndicators">Primer Menu</label>
<span class="ui-icon ui-icon-triangle-1-e menuIcon" style="float:right"></span>
<div id="subMenu" class="ui-accordion-header ui-helper-reset ui-state-default ui-corner-all">
<ul class="options">
<li>
<label class="formatText">Sub Menu Uno</label>
<span class="ui-icon ui-icon-triangle-1-s" style="float:right"></span>
<div id="subMenuRight" class="ui-accordion-header ui-helper-reset ui-state-default ui-corner-all">
<ul class=options>
<li>Sub-Sub Menu Uno</li>
<li>Sub-Sub Menu Dos</li>
</ul>
</div>
</li>
<li>Sub Menu Dos</li>
</ul>
</div>
</div>
这是我的 JQuery:
$(document).ready(initialize);
function initialize(){
$("#menu").hover(mouseIn,mouseOut);
$(".options li").hover(overOption,outOption);
$("#subMenu").hover(openRightMenu,closeRightMenu);
}
function mouseIn(){
$(this).find('span').attr('class','');
$(this).find('span').attr('class','ui-icon ui-icon-triangle-1-s');
$("#subMenu").slideDown(100);
}
function mouseOut(){
$(this).find('span').attr('class','');
$(this).find('span').attr('class','ui-icon ui-icon-triangle-1-e');
$("#subMenu").fadeOut(100);
}
function overOption(){
$(this).attr('class','ui-state-hover ui-corner-all');
}
function outOption(){
$(this).attr('class','');
}
function openRightMenu(){
$("#subMenuRight").slideDown(100);
}
function closeRightMenu(){
$("#subMenuRight").slideUp(100);
}
任何帮助将不胜感激!
I'm having a bug with the menu I'm developing, it all goes well until you mouse over a child of the menu fast.
The bug is also different on Firefox and Chrome, I think its because one render faster than the other, in Firefox it becomes an infinite bug, in Chrome it last for a few seconds, then it disappears.
Here's my html code:
<div id="menu" class="ui-accordion-header ui-helper-reset ui-state-default ui-corner-all">
<label class="formatText" id="lblIndicators">Primer Menu</label>
<span class="ui-icon ui-icon-triangle-1-e menuIcon" style="float:right"></span>
<div id="subMenu" class="ui-accordion-header ui-helper-reset ui-state-default ui-corner-all">
<ul class="options">
<li>
<label class="formatText">Sub Menu Uno</label>
<span class="ui-icon ui-icon-triangle-1-s" style="float:right"></span>
<div id="subMenuRight" class="ui-accordion-header ui-helper-reset ui-state-default ui-corner-all">
<ul class=options>
<li>Sub-Sub Menu Uno</li>
<li>Sub-Sub Menu Dos</li>
</ul>
</div>
</li>
<li>Sub Menu Dos</li>
</ul>
</div>
</div>
Here's my JQuery:
$(document).ready(initialize);
function initialize(){
$("#menu").hover(mouseIn,mouseOut);
$(".options li").hover(overOption,outOption);
$("#subMenu").hover(openRightMenu,closeRightMenu);
}
function mouseIn(){
$(this).find('span').attr('class','');
$(this).find('span').attr('class','ui-icon ui-icon-triangle-1-s');
$("#subMenu").slideDown(100);
}
function mouseOut(){
$(this).find('span').attr('class','');
$(this).find('span').attr('class','ui-icon ui-icon-triangle-1-e');
$("#subMenu").fadeOut(100);
}
function overOption(){
$(this).attr('class','ui-state-hover ui-corner-all');
}
function outOption(){
$(this).attr('class','');
}
function openRightMenu(){
$("#subMenuRight").slideDown(100);
}
function closeRightMenu(){
$("#subMenuRight").slideUp(100);
}
Here's a live demo on jsFiddle
Any help would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在创建新动画之前停止所有动画,这样它们就不会相互重叠。我添加了一些 .stop(true, true) 方法供您清除队列。 看看是否解决了您的问题
You need to stop all animations before creating new ones so they don't go over each other. I added some .stop(true, true) methods for your to clear your queue. Have a look if that sorted your problem