How Do Make a Jquery Collapsible Panel Collapsed instead of Expanded when the Document is Ready?

StackOverflow https://stackoverflow.com/questions/10306580

Question

I have following jquery code plugin:

           (function ($) {
                $.fn.extend({
                    collapsiblePanel: function () {
                        // Call the ConfigureCollapsiblePanel function for the selected element
                        return $(this).each(ConfigureCollapsiblePanel);
                    }
                });
            })(jQuery);

            function ConfigureCollapsiblePanel() {
                $(this).addClass("ui-widget");

                // Check if there are any child elements, if not then wrap the inner text within a new div.
                if ($(this).children().length == 0) {
                    $(this).wrapInner("<div></div>");
                }

                // Wrap the contents of the container within a new div.
                $(this).children().wrapAll("<div class='collapsibleContainerContent ui-widget-content'></div>");

                // Create a new div as the first item within the container.  Put the title of the panel in here.
                $("<div class='collapsibleContainerTitle ui-widget-header'><div>" + $(this).attr("title") + "</div></div>").prependTo($(this));


                // Assign a call to CollapsibleContainerTitleOnClick for the click event of the new title div.
                $(".collapsibleContainerTitle", this).click(CollapsibleContainerTitleOnClick);
            }


            function CollapsibleContainerTitleOnClick() {
                // The item clicked is the title div... get this parent (the overall container) 
                // and toggle the content within it.
                $(".collapsibleContainerContent", $(this).parent()).slideToggle();
            }

Then here is the html:

<div class="collapsibleContainer" title="Example Collapsible Panel">
                                    <p>
                                        KDLorem ipsum dolor sit amet, consectetur adipiscing elit.... (you get the idea!)
                                    </p>
                                </div>  

Then here is the css:

.collapsibleContainer
{
}

.collapsibleContainerTitle
{
   cursor:pointer;
}

.collapsibleContainerTitle div
{
  padding-top:5px;
  padding-left:10px;
}

.collapsibleContainerContent
{
   padding: 10px;
}

Here is the document ready function:

jQuery(function () {
   jQuery(".collapsibleContainer").collapsiblePanel();
});

What do I need to write to make the Panel actually collapse on document ready instead of expand as it is now doing when the document is loaded?

Était-ce utile?

La solution

Set the content of your panel to display:none.

Looks like the plugin uses slideToggle(), which just animates transition to/from display:none.

So, I think this:

.collapsibleContainerContent
{
   padding: 10px;
   display: none;
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top