Jquery close toggle when other toggle is open

2019-05-27 11:19发布

I have two sliding panels, panel1 is sliding down, while panel2 is sliding from left. I want to close panel1 when opening panel2. I know there's many similar question already been answered but I couldn't figure it out how do I apply those in my site.

$(document).ready(function(){
  $(".slide-btn1").click(function(){
    $("#panel1").toggle("slow");
    $(this).toggleClass("active");
    return false;
  });
  $(".slide-btn2").click(function(){
    $("#panel2").slideToggle("slow");
    $(this).toggleClass("active");
    return false;
  });
});

Edit: this is what I have done so far http://jsfiddle.net/Pukau/9CFgR/2/

标签: jquery toggle
1条回答
Luminary・发光体
2楼-- · 2019-05-27 12:09
$(document).ready(function(){
    $(".slide-btn1").click(function(){
           $("#panel2").slideUp("fast");
            $('.active').removeClass('active');
        $("#panel1").toggle("fast");
        $(this).toggleClass("active");
        return false;
    });
        $(".slide-btn2").click(function(){
             $("#panel1").slideUp("fast");
           $('.active').removeClass('active');
        $("#panel2").slideToggle("slow");
        $(this).toggleClass("active");
        return false;
    });
});​

for live demo see this link: http://jsfiddle.net/nanoquantumtech/HT9Bx/

查看更多
登录 后发表回答