jquery菜单幻灯片错误
问题描述:
我目前正在制作一个网站,其中包含的菜单导航几乎与fotopunch.com中找到的菜单几乎相同,而不是指向它的点。无论如何,我写了代码使用jquery/JavaScript的菜单,它的工作原理,但也有一个小错误,也发生在fotopunch网站。 当您将光标从一个菜单项移动到另一个菜单项并重复返回时,会暂时使显示屏失灵。有没有办法来解决这个问题?我将包含我的JavaScript文件的一部分,以便您可以查看我为每个菜单项所做的操作。jquery菜单幻灯片错误
$("div#menu .reps").hover(function() {
//if the current slide is not reps
if(current_slide != "reps"){
//move the arrow to the corresponding position for the reps slide
$(".arrow").animate({"left":"135px"});//move the arrow
//(test which slide it is.)
if(current_slide == "clients"){
//fade out & hide the current slide
$(".clients_display").fadeOut().hide();//hide the current slide
//show the reps slide & fade in
$(".reps_display").fadeIn().show();//show the slide
//the current slide is the reps slide
current_slide = "reps";
}
else if(current_slide == "services"){
//fade out & hide the current slide
$(".services_display").fadeOut().hide();//hide the current slide
//show the reps slide & fade in
$(".reps_display").fadeIn().show();//show the slide
//the current slide is the reps slide
current_slide = "reps";
}
else{
//fade out & hide the current slide
$(".training_display").fadeOut().hide();//hide the current slide
//show the reps slide & fade in
$(".reps_display").fadeIn().show();//show the slide
//the current slide is the reps slide
current_slide = "reps";
}
}
});
我为每个菜单项目(有4个)做这个。我认为问题是当它淡出并淡入时,因为如果它试图同时做太多,它同时显示2个菜单div。我试图添加超时但不成功。 修复此错误的最佳方法是什么?它足够小,不会成为一个重要的优先事项,但它会更好地工作。谢谢。
答
if(current_slide == "clients"){
$(".clients_display")stop(true, true).fadeOut().hide();
$(".reps_display").stop(true, true).fadeIn().show();
current_slide = "reps";
} else if(current_slide == "services"){
$(".services_display").stop(true, true).fadeOut().hide();
$(".reps_display").stop(true, true).fadeIn().show();
current_slide = "reps";
} else{
$(".training_display").stop(true, true).fadeOut().hide();//hide the current slide
$(".reps_display").stop(true, true).fadeIn().show();//show the slide
}
您是否尝试过http://api.jquery.com/stop/? – j08691
很酷。停止功能确实修复了它。但是当来回移动时,箭头仍然滞后。 – fudge22it