开发者

toggling jquery animation getting error

开发者 https://www.devze.com 2022-12-13 21:06 出处:网络
Im trying to have a layer animate/expand hight on click of a \"show\" button, and then, within the layer, have a button to hide it back to 0.

Im trying to have a layer animate/expand hight on click of a "show" button, and then, within the layer, have a button to hide it back to 0.

 开发者_开发技巧   $(".showcart").click(
        function(){ $("#cart").animate({ height: "400px" }); $(".showcart").toggle();});
            $(".hidecart").click(function(){
            $("#cart").animate({height: "0px"});
        }); 

});

Not sure where the problem is, any ideas?


Try wrapping your code inside the DOM ready event...

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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号