我試圖用jQuery實現簡單的動畫。這是我的代碼:隱藏和顯示左面板的jQuery動畫方法
<div>
<div id="leftPannel" style="height: 500px; width: 200px; background-color: Olive;
float: left; display: none">
</div>
<div id="rest" style="height: 500px; width: 400px; float: left; margin-left: 10px;
background-color: Purple">
<input type="button" id="Display" value="Display" /></div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#Display').click(function() {
var status = $('#leftPannel').css("display");
if (status == "none") {
$('#leftPannel').animate({ display: 'show' }, "slow")
}
else {
$('#leftPannel').animate({ display: 'hide' }, "slow")
}
});
});
</script>
問題是當左側面板被隱藏,它顯示與點擊事件。但再次點擊它不會再隱藏。爲什麼其他人沒有執行?
@ user1784622,請注意,通過這種方式,您還可以使用'toggle'作爲值 – Abhilash
是的其他參數,例如'height','opacity'等等,這很好用。 – user1784622