0
我有三個信息框,希望用我已經編碼的特定動畫打開。我已經編碼了所有被點擊的地方,其他地方都關閉了,但是我似乎無法弄清楚的是如何在第二次點擊該名稱時關閉該框,並且我不知道爲什麼,但是當我嘗試切換事件不起作用。任何想法我怎麼能做到這一點?這裏是jQuery代碼:使用jquery在第二次點擊時反轉動畫
$('.link').click(function(){
$('#box').animate({
marginLeft:"0px",
marginTop:"100px"
},500).addClass('navigation').animate({
width:"260px",
height:"80px"
},500);
$('#box2').animate({
marginLeft:"100px",
marginTop:"0px",
width:"60px",
height:"23px"
},500).removeClass('navigation');
$('#box3').animate({
marginLeft:"200px",
marginTop:"0px",
width:"60px",
height:"23px"
},500).removeClass('navigation')
});
$('.link2').click(function(){
$('#box2').animate({
marginLeft:"0px",
marginTop:"100px"
},500).addClass('navigation').animate({
width:"260px",
height:"80px"
},500);
$('#box').animate({
marginLeft:"0px",
marginTop:"0px",
width:"60px",
height:"23px"
},500).removeClass('navigation');
$('#box3').animate({
marginLeft:"200px",
marginTop:"0px",
width:"60px",
height:"23px"
},500).removeClass('navigation');
});
$('.link3').click(function(){
$('#box3').animate({
marginLeft:"0px",
marginTop:"100px"
},500).addClass('navigation').animate({
width:"260px",
height:"80px"
},500);
$('#box2').animate({
marginLeft:"100px",
marginTop:"0px",
width:"60px",
height:"23px"
},500).removeClass('navigation');
$('#box').animate({
marginLeft:"0px",
marginTop:"0px",
width:"60px",
height:"23px"
},500).removeClass('navigation');
});
這裏是一個要的jsfiddle使其更加明確:http://jsfiddle.net/Unphr/11/
非常感謝!我現在需要更多地探索.data():) – 2013-03-14 01:53:14
你可能也喜歡這個例子:http://jsfiddle.net/Unphr/12/。它也保存了原始的寬度/高度,並根據需要進行恢復。 – istos 2013-03-14 02:00:22
哇,那個太酷了!嘿,在點擊動畫之後,如何讓高度等於「自動」,以便它始終適合正確的高度?在動畫事件中,因爲自動迴應不好 – 2013-03-14 05:11:45