Panel open closed JS

6

I have the following panel:

$(document).on('click', '.panel-heading', function(e){
    var $this = $(this);
    if(!$this.hasClass('panel-collapsed')) {
        $this.parents('.panel').find('.panel-body').slideUp();
        $this.addClass('panel-collapsed');
        $this.find('i').removeClass('glyphicon-menu-up').addClass('glyphicon-menu-down');
    } else {
        $this.parents('.panel').find('.panel-body').slideDown();
        $this.removeClass('panel-collapsed');
        $this.find('i').removeClass('glyphicon-menu-down').addClass('glyphicon-menu-up');
        $('html, body').animate({scrollTop: $(".btn-modal").offset().top}, 1000);
    }
});

My question is: I can not get it to start closed (without collapse), that is, only after clicking it will it appear and go down, and clicking again will return to the closed format. What do I do?

    
asked by anonymous 30.04.2015 / 08:28

2 answers

1

Try putting .ready to close all panels

$(document).ready(function() {
    $('.panel-heading').each(function (index) {
        var $this = $(this);
        if(!$this.hasClass('panel-collapsed')) {
            $this.parents('.panel').find('.panel-body').slideUp();
            $this.addClass('panel-collapsed');
            $this.find('i').removeClass('glyphicon-menu-up').addClass('glyphicon-menu-down');
        }
    });
});
    
28.06.2015 / 00:06
0

Hitch, as you did not post the full code, I noticed that you are using Bootstrap Collapse

If you need to leave all collaps closed at the beginning it's very simple, you just remove the class in in the div of the content that is visible:

Example: jsfiddle

    
07.10.2015 / 13:42