简体   繁体   中英

jquery accordion default expanded

Working on a project and I am using jQuery's accordion lib. I want all items in the submenu to be expanded by default. Here is the code:

<script type="text/javascript">
$jsmart(document).ready(function($) {
    $('#yt_sidenav li.level0 > a').addClass ('subhead');
    $('#yt_sidenav li.level0 > a').after ('<a href="#" title="" class="toggle">&nbsp;</a>');    //header 

    ////////////////////
    //$('#yt_sidenav li ul li').has('ul').append( '<span class="more-item-nav">open</span>' );

        var speed=200;
        $('#yt_sidenav li ul li').has('ul').append( '<span class="touch-item">open</span>' );

        $('.touch-item').click(function(){
            $(this).prev().slideToggle(speed);
            $(this).toggleClass('change');
            $(this).prev().prev().toggleClass('parentNote');
        });
    // second simple accordion with special markup
    $jsmart('#yt_sidenav').accordion({
        active: '.active',
        header: '.toggle',      // same header above
        navigation: true,
        event: 'click',
        fillSpace: false,
        autoheight: false,
        alwaysOpen: false, 
        animated: 'easeslide',
        collapsible: false
    }); 

    //check if headerId is set, if so activate that id
    if ($jsmart("#yt_sidenav .level2 .current").parents('.parent').length) {
        var header_element = $jsmart("#yt_sidenav .level2 .current").parents('.parent').children('a.toggle')
        $jsmart('#yt_sidenav').accordion('activate', header_element);
    }           

});
</script>

I have looked at the documentation, and have come to the conclusin .index() should be used to expand all by default. But I am lost to where I need to add this code.

Could you please have a look?

Thanks in advance.

From the jquery collapsible documentation ... By default, accordions always keep one section open. To allow for all sections to be be collapsible, set the collapsible option to true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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