View Full Version : Open all sections at once?
fred2028
02-05-2009, 02:45 AM
1) Script Title: Accordion menu
2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ddaccordionmenu-glossy.htm
3) Describe problem: Is it possible to open all menus at once on page load?
ddadmin
02-05-2009, 06:19 AM
Just set the following two parameters when initializing a menu:
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:
persiststate: false, //persist state of opened contents within browser session?
Snookerman
02-05-2009, 06:27 AM
Sure, find this line in the beginning of your code:
defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
and add numbers in the brackets, starting with zero:
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!
fred2028
02-05-2009, 04:38 PM
Thanks a lot! I'll give that a shot.
fred2028
02-05-2009, 06:20 PM
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?
ddadmin
02-06-2009, 08:00 AM
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:
defaultexpanded: [],
Then use the oninit() (http://www.dynamicdrive.com/dynamicindex17/ddaccordion_suppliment2.htm) parameter/ event handler to dynamically expand all the headers if there are less than 5 headers total on the page:
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)
},
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.