2009-12-07 21 views
0

我試着去有一個層動畫/擴展HIGHT上的「顯示」按鈕的點擊,然後在層內,有一個按鈕,以隱藏它回0撥動jQuery的動畫收到錯誤

$(".showcart").click(
     function(){ $("#cart").animate({ height: "400px" }); $(".showcart").toggle();}); 
      $(".hidecart").click(function(){ 
      $("#cart").animate({height: "0px"}); 
     }); 

}); 

不知道問題出在哪裏,有什麼想法?

+0

你得到什麼錯誤? – marcgg 2009-12-07 11:09:49

回答

1

嘗試包裹的DOM ready事件裏面的代碼......

$(function() { 
    $(".showcart").click(function(){ 
     $("#cart").animate({ height: "400px" }); 
     $(".showcart").toggle(); 
    }); 
    $(".hidecart").click(function(){ 
     $("#cart").animate({height: "0px"}); 
    }); 
}); 
1
$(".showcart").click(function(){ 
     $("#cart").animate({ height: "400px" }); 
     $(".showcart").toggle();}); 
     $(".hidecart").click(function(){ 
        $("#cart").animate({height: "0px"}); 
     }); 
});