2016-03-09 127 views
1

開始按鈕和完成按鈕不起作用,因爲我已經給他們兩個ID。我想開始有生命的,當我點擊完成它應該完成動畫動畫和完成動畫使用jQuery

<script src="jquery-2.2.1.min.js"></script> 
<script> 

$(document).ready(function() 
{ 
    $("#start_Animate").click(function() 
    { 
     $("div").animate(2000); 
    }); 
    $("#finish_Animate").click(function() 
    { 
     $("div").finish(); 
    }); 
}); 

</script> 
</head> 

<body> 
<button id="start_Animate">Start Animate</button> 
<button id="finish_Animate">Stop Animate</button> 
<div style="background-color:#900; width:400px; display:none; height:300px"></div> 
</body> 
</html> 

回答

1

當你調用生命的,你應該告訴它什麼也做,在這種情況下,你可以使用簡單show(2000)顯示元素

$(document).ready(function() { 
 
    $("#start_Animate").click(function() { 
 
    //$("div").show(2000) 
 
    $("div").animate({ 
 
     width: ["toggle", "swing"], 
 
     height: ["toggle", "swing"] 
 
    }, 2000, "linear"); 
 
    }); 
 
    $("#finish_Animate").click(function() { 
 
    $("div").finish(); 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<button id="start_Animate">Start Animate</button> 
 
<button id="finish_Animate">Stop Animate</button> 
 
<div style="background-color:#900; width:400px; display:none; height:300px"></div>

+0

Actully我想製作動畫,當我點擊這裏開始按鈕--- $( 「#start_Animate」)。點擊(函數(){$ ( 「格」)。顯示(2000) <<<這裏我想要動畫(3000); }); – Shanky

+0

是的....當你點擊開始按鈕時,它是動畫... –

+0

我很感謝您的幫助。但我的意圖是使用動畫功能,而不是show() – Shanky