jquery SlideUp 菜单切换?
我有一个向上滑动菜单,它的行为不稳定,有时如果我快速滑动它,它可能会上下滑动 4 或 5 次。在其他时候,如果我在正确加载之前将鼠标悬停在它上面,菜单将向上滑动并成为其“正常”状态,这样如果我将鼠标悬停在它上面,它就会在我有机会单击任何菜单项之前向下滑动。
这是代码:
$(document).ready(function(){
var opened = false;
$("#menu_box").hover(function(){
if(opened){
$("#menu_box").animate({"top": "+=97px"}, "200");
}
else{
$("#menu_box").animate({"top": "-=97px"}, "200");
}
$("#menu_content").slideToggle("200");
$("#menu_tab .close").toggle();
opened = !opened;
});
})
该代码最初是一个单击功能,而不是悬停功能,所以我尝试将其修改为以下内容:
$(document).ready(function(){
$("#menu_box").hover(function(){
$("#menu_box").toggle(function(){
$("menu_box").animate({"top": "-=97px"}, "200");
$("#menu_content").slide("200");
});
});
});
但这只是使菜单从右向左淡出 - 根本不滑动。
我哪里出错了?蒂亚!
I have a slideUp menu, which is acting erratically in that sometimes if I flick too quickly across it, it slides up and down maybe 4 or 5 times. At other times, if I hover over it before it's finished loading properly, the menu will slideUp and that becomes its "normal" state so that if I hover over it, it slides down before I have a chance to click any menu items.
Here is the code:
$(document).ready(function(){
var opened = false;
$("#menu_box").hover(function(){
if(opened){
$("#menu_box").animate({"top": "+=97px"}, "200");
}
else{
$("#menu_box").animate({"top": "-=97px"}, "200");
}
$("#menu_content").slideToggle("200");
$("#menu_tab .close").toggle();
opened = !opened;
});
})
The code was originally a click function, rather than hover, so I tried amending it to the following:
$(document).ready(function(){
$("#menu_box").hover(function(){
$("#menu_box").toggle(function(){
$("menu_box").animate({"top": "-=97px"}, "200");
$("#menu_content").slide("200");
});
});
});
But that just made the menu fade from right to left - not sliding at all.
Where am I going wrong? TIA!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用绑定 mouseenter/mouseleave 而不是悬停修复了它!
Fixed it with bind mousenter/mouseleave instead of hover!