我有一系列关于关闭切换用下面的代码盒(标签):jQuery多重切换动画,当一个动画中断另一个动画时出错?
<script type="text/javascript" src="jquery-1.4.3.min.js"></script>
<script type="text/javascript">
isShowing = false;
whichIsShowing = new Array();
$(function() {
$(".normal").hover(
function() {
$(this).toggleClass("highlight");
},
function() {
$(this).toggleClass("highlight");
}
);
$("div").toggle(
function() {
if (isShowing == false) {
$(this).animate({width: "500px", height: "500px"}, 1000);
isShowing = true;
whichIsShowing.push($(this).attr('id'));
$("#display").replaceWith("<div id='display' class='title'>Which div is showing? " + whichIsShowing[0] + "</div>");
} else {
$("#" + whichIsShowing.pop()).animate({width: "175px", height: "175px"}, 1000);
$(this).animate({width: "500px", height: "500px"}, 1000);
whichIsShowing.push($(this).attr('id'));
$("#display").replaceWith("<div id='display' class='title'>Which div is showing? " + whichIsShowing[0] + "</div>");
}
},
function() {
if (isShowing == true) {
$("#" + whichIsShowing.pop()).animate({width: "175px", height: "175px"}, 1000);
isShowing = false;
$("#display").replaceWith("<div id='display' class='title'>Which div is showing? " + "none" + "</div>");
}
}
);
});
</script>
<style type="text/css">
.normal {
width: 175px;
height: 175px;
border:2px solid #333333;
background: Silver;
float: left;
margin-right: 20px;
cursor: pointer;
}
.title {
clear: both;
}
.highlight {
background: #FFCC00;
}
</style>
其中DIV是显示:
这个问题似乎是,如果我点击太快的框,然后我有多个盒子“同时动画”,这不是我想要的(我只想要一个盒子在任何时候都处于“动态”状态)。
有没有什么办法可以防止一个盒子在动画中间时出现动画?或者停止当前的动画,倒转它,并在NEW框中设置动画效果?