Question

There's a fiddle here.

I'm trying to have the panels collapsed on default by adding...

$container.active(false);

And it does collapse the panels, but then it also disrupts other jquery plugins on the page.

Here's the full script:

(function() {

    var $container = $('.acc-container'),
        $trigger   = $('.acc-trigger');

    $container.hide();
    $container.active(false);
    $trigger.first().addClass('active').next().show();

    var fullWidth = $container.outerWidth(true);
    $trigger.css('width', fullWidth);
    $container.css('width', fullWidth);

    $trigger.on('click', function(e) {
        if( $(this).next().is(':hidden') ) {
            $trigger.removeClass('active').next().slideUp(300);
            $(this).toggleClass('active').next().slideDown(300);
        }
        e.preventDefault();
    });

    // Resize
    $(window).on('resize', function() {
        fullWidth = $container.outerWidth(true)
        $trigger.css('width', $trigger.parent().width() );
        $container.css('width', $container.parent().width() );
    });

})();

Where did I go wrong?

Était-ce utile?

La solution

Let's write some negative code. Remove your fix attempt, it was causing an error, thats why all other scripts stopped working.

$container.active(false);

Then remove the next line. Here first item of the accordion was expanded:

$trigger.first().addClass('active').next().show();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top