我有一系列關於關閉切換用下面的代碼盒(標籤):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框中設置動畫效果?