Skip to content Skip to sidebar Skip to footer

How To Make Only One Accordion Slide Open At A Time

I have a site I'm working on that is all based on accordion style slides. The problem is that the code I used does not close the open slides by default. I need it so that when you

Solution 1:

You could change the class of the item clicked.

$('.accordion-toggle').click(function() {

    for (c=0;c<$('.collapse').length;c++){
        $("#"+$('.collapse')[c].id).collapse('hide');
    }

    $('html,body').animate({scrollTop: $(this).offset().top - 105}, 800);
});

So when you click at a .menu-item you can get all .menu-item-clicked and change them to close.

Solution 2:

jQueryUI has some very useful widgets, including accordions. Please use that, instead of trying to recreate the behavior. (Unless you want to find out how it works, creating something for learning purposes is valid. But then your question should specify that.)

Post a Comment for "How To Make Only One Accordion Slide Open At A Time"