Open all accordion windows at the same time

后端 未结 3 561
深忆病人
深忆病人 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

    Section 1

    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.

    Section 2

    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.

    Section 3

    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.

    • List item one
    • List item two
    • List item three

    Section 4

    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.

    Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.


    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!

提交回复
热议问题