简体   繁体   English

切换jQuery动画获取错误

[英]toggling jquery animation getting error

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. 我试图单击“显示”按钮使图层动画化/展开,然后在该图层内使用按钮将其隐藏为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? 不知道问题出在哪里,有什么主意吗?

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

Try wrapping your code inside the DOM ready event... 尝试将代码包装在DOM ready事件中...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM