我目前在jQuery動畫方面遇到了很多麻煩。基本上,點擊按鈕可以快速啓動一個簡短的動畫並摺疊側邊欄,將主內容框擴展爲全角(如果需要,可以再次返回)。問題在於,通過快速連續的點擊,佈局變得瘋狂。我試過這個條件:
if (!$(this).is(":animated"))
{
// Code
}
但它不起作用。所以我嘗試了.off(),它關閉了,但是我找不到如何將它恢復.on()。有人能幫助我嗎?以下是我有:
<script type="text/javascript">
$(document).ready(function(){
var $button = $("a#toggle");
var $content = $("div#index_main-content");
var $sidebar = $("div#sidebar");
// Disable quicky clicky
$button.click(function() {
$button.off().delay(1000).on();
});
// Hide sidebar
$button.toggle(function sidebarToggle() {
$sidebar.fadeOut(500, function() {
$content.animate({width: '100%'}, 500, function() {
$button.attr("title", "Click to show the sidebar!").addClass("hiding").removeClass("showing");
});
});
},
// Show sidebar
function sidebarToggle() {
$content.animate({width: '69.5%'}, 500, function() {
$sidebar.fadeIn(500, function() {
$button.attr("title", "Click to hide the sidebar!").addClass("showing").removeClass("hiding");
});
});
});
});
</script>
<div id="index_content">
<a title="Click to hide the sidebar" class="showing" id="toggle"></a>
<div id="sidebar">
<!-- Sidebar: float-right/width-28.5% -->
</div>
<div id="index_main-content">
<!-- Content: float-left/width-69.5% -->
</div>
</div>
此外,還有現場演示here。就像我之前說過的,出於某種原因,.on()不會發生。 :(
謝謝:)
你把'.is(':animated')'放在哪裏? – Blender 2012-02-03 05:07:26
爲什麼你重新定義sidebarToggle? – 2012-02-03 05:11:21
我只想要一個名字。 :P和我沒有使用.is ..因爲那是以前的測試,並且它什麼也沒做 – sackbot14 2012-02-05 06:49:31