【发布时间】:2013-01-15 18:52:44
【问题描述】:
在我的页面中,我有不同的菜单项触发不同的相应图片。 z-index 将对应的图片切换到顶部。代码如下:
$(document).ready(function(){
var doorOpen = false;
$("a[href=#andrew]").click(function() {
if (doorOpen) { // set animation duration for door close, based on actually needed to animate the door closed or not
var duration = 1500;
} else {
var duration = 0;
}
$("#rightdoor,#leftdoor").animate(
{"marginLeft":"0px"},
{duration:duration,
complete:function() {
$('.pic2 .pic3 .pic4 .pic5').css('zIndex', 1); //puts wrong pics in back
$('.pic1').css('zIndex', 2); //brings right pic into view
$('#rightdoor').animate({ //opens doors again
marginLeft: "150px",
}, 1500);
$('#leftdoor').animate({
marginLeft: "-150px",
}, 1500);
}
}
);
doorOpen = true;
});
$("a[href=#bugz]").click(function() {
if (doorOpen) { // set animation duration for door close, based on actually needed to animate the door closed or not
var duration = 1500;
} else {
var duration = 0;
}
$("#rightdoor,#leftdoor").animate(
{"marginLeft":"0px"},
{duration:duration,
complete:function() {
$('.pic1 .pic3 .pic4 .pic5').css('zIndex', 1); //puts wrong pics in back
$('.pic2').css('zIndex', 2); //brings right pic into view
$('#rightdoor').animate({ //opens doors again
marginLeft: "150px",
}, 1500);
$('#leftdoor').animate({
marginLeft: "-150px",
}, 1500);
}
}
);
doorOpen = true;
});
});
问题是z-index 有效,但每个菜单项似乎只有一次。如果您最初单击#andrew,它会将 pic1 带到顶部,如果您单击 #bugz,它会将 pic2 带到顶部。但是,如果您再次单击 #andrew,它会在 .css(z-index) 更改之前和之后为代码设置动画,但不会更改 z-index 以将 pic1 带回顶部。
我是 Javascript/JQuery 的新手,所以如果我遗漏了一些明显的东西,请原谅我
【问题讨论】:
标签: javascript jquery jquery-animate z-index animate.css