Open all accordion windows at the same time

后端 未结 3 559
深忆病人
深忆病人 2021-01-21 17:30

I am using jQuery accordion plugin for my application. Is there a way to open sections at the same time(after page has loaded) so that contents of all pages are shown at the sam

相关标签:
3条回答
  • 2021-01-21 17:54

    Solution With Theme!

    without a plugin It's really very simple. Use the same mark-up as normal accordion. Copy the classes from a normal accordion to your markup. Add a "little" JavaScript magic and viola!

    jsFiddle Example (with Theme Switcher!)


    The HTML

    <div id="StickyNotes">
        <div class="container">
            <div id="accordion" class="ui-accordion ui-widget ui-helper-reset">
                <h3 class="ui-accordion-header ui-helper-reset ui-state-default ui-accordion-icons ui-corner-top ui-accordion-header-active ui-state-active">
                    <span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-s"></span>
                    Section 1
                </h3>
                <div class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active">
                    <p>
                        Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
                        ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
                        amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
                        odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
                    </p>
                </div>
                <h3 class="ui-accordion-header ui-helper-reset ui-state-default ui-accordion-icons ui-corner-top ui-accordion-header-active ui-state-active">
                    <span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-s"></span>
                    Section 2
                </h3>
                <div class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active">
                    <p>
                        Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet
                        purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor
                        velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In
                        suscipit faucibus urna.
                    </p>
                </div>
                <h3 class="ui-accordion-header ui-helper-reset ui-state-default ui-accordion-icons ui-corner-top ui-accordion-header-active ui-state-active">
                    <span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-s"></span>
                    Section 3
                </h3>
                <div class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active">
                    <p>
                        Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis.
                        Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero
                        ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis
                        lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui.
                    </p>
                    <ul>
                        <li>List item one</li>
                        <li>List item two</li>
                        <li>List item three</li>
                    </ul>
                </div>
                <h3 class="ui-accordion-header ui-helper-reset ui-state-default ui-accordion-icons ui-corner-top ui-accordion-header-active ui-state-active">
                    <span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-s"></span>
                    Section 4
                </h3>
                <div class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active">
                    <p>
                        Cras dictum. Pellentesque habitant morbi tristique senectus et netus
                        et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in
                        faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia
                        mauris vel est.
                    </p>
                    <p>
                        Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus.
                        Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
                        inceptos himenaeos.
                    </p>
                </div>
            </div>
        </div>
    </div>
    

    The JavaScript

    $(function() {
        $("#accordion > h3").on("click", function(e) {
            $(this).next().slideToggle(function(e) {
                if ($(this).is(":visible")) {
                    $(this).addClass("ui-accordion-content-active")
                    .prev().toggleClass("ui-corner-all ui-corner-top").addClass("ui-accordion-header-active ui-state-active")
                    .children(".ui-accordion-header-icon").toggleClass("ui-icon-triangle-1-e ui-icon-triangle-1-s");
                }
                else {
                    $(this).removeClass("ui-accordion-content-active")
                    .prev().toggleClass("ui-corner-all ui-corner-top").removeClass("ui-accordion-header-active ui-state-active")
                    .children(".ui-accordion-header-icon").toggleClass("ui-icon-triangle-1-e ui-icon-triangle-1-s");
                }
            });
        })
        .hover(function(e) { $(this).toggleClass("ui-state-hover"); });
    })
    

    Of course, if you still want a jQueryUI Theme Compatible (or so they claim, personally untested) Plugin to add to your Libs, you can find one here!

    0 讨论(0)
  • 2021-01-21 17:58

    You should read NOTES in this page. Here I copy and pasted it directly from that page:

    NOTE: If you want multiple sections open at once, don't use an accordion

    An accordion doesn't allow more than one content panel to be open at the same time, and it takes a lot of effort to do that. If you are looking for a widget that allows more than one content panel to be open, don't use this. Usually it can be written with a few lines of jQuery instead, something like this:

    jQuery(document).ready(function(){
        $('.accordion .head').click(function() {
            $(this).next().toggle();
            return false;
        }).next().hide();
    });
    

    Or animated:

    jQuery(document).ready(function(){
        $('.accordion .head').click(function() {
            $(this).next().toggle('slow');
            return false;
        }).next().hide();
    });
    
    0 讨论(0)
  • 2021-01-21 18:08

    jQuery makes it very easy to make your own accordion without a plugin. For example, this HTML:

    <div class="accordion_toggler">
        Section One
    </div>
    
    <div class="accordion_content">
        ..... content here ......
    </div>
    

    and this jQuery:

    $('.accordion_toggler').click(function() {
        $(this).next('.accordion_content').slideToggle();
    });
    

    Any time you click on an accordion_toggler , the following accordion_content will toggle (slide up or down in this case). To start with all the content hidden but allow multiple to be open at the same time, use this CSS:

    .accordion_content { display: none }
    
    0 讨论(0)
提交回复
热议问题