Results 1 to 6 of 6

Thread: Open all sections at once?

  1. #1
    Join Date
    Sep 2005
    Posts
    34
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Open all sections at once?

    1) Script Title: Accordion menu

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...enu-glossy.htm

    3) Describe problem: Is it possible to open all menus at once on page load?

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Just set the following two parameters when initializing a menu:

    Code:
    	collapseprev: false, //Collapse previous content (so only one open at any time)? true/false 
    	defaultexpanded: [0,1], //index of content(s) open by default [index1, index2, etc] [] denotes no content
    with 0,1 being the indices of your menu headers. Depending on the # of expandable headers you have, change this value.

    You may also want to set persist to false:

    Code:
    	persiststate: false, //persist state of opened contents within browser session?
    DD Admin

  3. #3
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    Sure, find this line in the beginning of your code:
    Code:
    defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
    and add numbers in the brackets, starting with zero:
    Code:
    defaultexpanded: [0,1,2,3,4], //index of content(s) open by default [index1, index2, etc] [] denotes no content
    So if you have five menus, you count to four.

    Good luck!

  4. #4
    Join Date
    Sep 2005
    Posts
    34
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thanks a lot! I'll give that a shot.

  5. #5
    Join Date
    Sep 2005
    Posts
    34
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Oh wait, this makes all the menu items open at once on every page (I use an SSI type tool to include the header code on every page). Is it possible to make it all open only on pages that have less than 5 menu items?

  6. #6
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    You can get the headers to expand conditionally based on how many headers there are in total on the page by doing the below:

    1) Keep the changes suggested above for the parameter settings except "defaultexpanded". Revert it back to none:

    Code:
    defaultexpanded: [],
    Then use the oninit() parameter/ event handler to dynamically expand all the headers if there are less than 5 headers total on the page:

    Code:
    	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
    		var limit=Math.min(headers.length, 5)
    		for (var i=0; i<limit; i++)
    			ddaccordion.expandone(this.headerclass, i)
    	},
    DD Admin

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •