Reply
Looking for expanding & collapsing menu script
Old 09-04-2008, 04:36 PM Looking for expanding & collapsing menu script
tonya's Avatar
Ultra Talker

Posts: 423
Location: world traveller based in UK
I am looking for some good expanding & collapsing menu script.

I have been recommended this

http://www.howtocreate.co.uk/tutoria...seExample.html

The only problem is the guy that wrote it doesn't really expect non developers to mess about with the code & although I now have it working as per his examples the one thing his examples don't allow for are links in the menu that have no sub links or child nodes as he calls them

So perhaps there are some smart javascript developers out there who can tell me how to work the script so that I can have simple straight links or

Maybe someone has some other code they can recommend either of their own or another free resource

Thanks
__________________
Tonya

:: my personal site :: Marine Biology Site
tonya is offline
Reply With Quote
View Public Profile Visit tonya's homepage!
 
When You Register, These Ads Go Away!
Old 09-04-2008, 04:37 PM Re: Looking for expanding & collapsing menu script
tonya's Avatar
Ultra Talker

Posts: 423
Location: world traveller based in UK
My example is here

http://www.bitsmail.co.uk/cloudsend/...st-basic3.html

Thanks
__________________
Tonya

:: my personal site :: Marine Biology Site
tonya is offline
Reply With Quote
View Public Profile Visit tonya's homepage!
 
Old 09-07-2008, 06:47 PM Re: Looking for expanding & collapsing menu script- PLEASE HELP !!
tonya's Avatar
Ultra Talker

Posts: 423
Location: world traveller based in UK
I am still completely stuck

Here is some basic HTML

Quote:
<ul id="odo2">
<li>Book 1
<ul>
<li><a href="list-basic3.html">Chapter 1</a></li>
<li><a href="list-basic3.html">Chapter 2</a></li>
<li><a href="list-basic3.html">Chapter 3</a></li>
<li><a href="list-basic4.html">Chapter 4</a></li>
</ul>
</li>
<li class="two">Book 2
<ul>
<li><a href="list-basic3.html">Chapter 1</a></li>
<li><a href="list-basic3.html">Chapter 2</a></li>
<li>Chapter 3
<ul>
<li><a href="list-basic3.html">Ex 1</a></li>
<li><a href="list-basic3.html">Ex 2</a></li>
</ul>
</li>
<li><a href="list-basic3.html">Chapter 4</a></li>
</ul>
</li>
<li>Book 3
<ul>
<li><a href="list-basic4.html">Chapter 1</a></li>
<li><a href="list-basic4.html">Chapter 2</a></li>
<li><a href="list-basic4.html">Chapter 3</a></li>
<li><a href="list-basic4.html">Chapter 4</a></li>
</ul>
</li>
<li><a href="list-basic4.html" class="SomeId2">Book 4</a></li>
<li><a href="list-basic4.html" class="SomeId2">Book 5</a> </li>
</ul>
I want it to expand & collapse when the user clicks on sub menu's they stay open to allow user to browse the sub menu but then collapse when user clicks somewhere else even on a menu option which has no submenu.

Anyone who has done this PLEASE PLEASE can you help me !!!!!!
__________________
Tonya

:: my personal site :: Marine Biology Site
tonya is offline
Reply With Quote
View Public Profile Visit tonya's homepage!
 
Old 09-07-2008, 06:49 PM Re: Looking for expanding & collapsing menu script
tonya's Avatar
Ultra Talker

Posts: 423
Location: world traveller based in UK
If I need to paste the whole script here I can - BUT I REALLY REALLY NEED HELP !!!!
__________________
Tonya

:: my personal site :: Marine Biology Site
tonya is offline
Reply With Quote
View Public Profile Visit tonya's homepage!
 
Old 09-07-2008, 07:23 PM Re: Looking for expanding & collapsing menu script
chrishirst's Avatar
Super Moderator

Posts: 15,313
Location: Blackpool. UK
www . creeme.inyoursite.co.uk/ work in progress on a test site so I don't want to link to it.


Code:
/ drop down menu functions
var currentNav = null;

function openNav(obj) {
if (obj == null) {
//	obj = currentNav;
}
	if (obj.className.match("closed") != null) {
		closeAll();
		obj.className = obj.className.replace("closed","open");
	} else {
		closeNav(obj);
	}

	if (currentNav != null) {
		closeNav(currentNav);
	}
//	currentNav = obj;
}

function closeNav(obj) {
		obj.className = obj.className.replace("open","closed");
	obj = null;
}

function closeAll() {
var children = document.getElementsByTagName("DL");
	for (var i = 0;i < children.length; i++) {
		children[i].className = children[i].className.replace("open","closed");
	}
}

function setClose() {
//	window.setTimeout("closeNav()",1500);
}
Applied to a definition list but the principle is the same.
HTML Code:
<dl id="artcat_1" class="open" onclick="openNav(this)">
<dt>Tribute Acts</dt>

<dd><a href="/artists/the-beatles/">Beatles</a></dd>

<dd>Abba</dd>

<dd id="close_mnu">Close</dd>
</dl>
<dl id="artcat_2" class="open" onclick="openNav(this)">
<dt>Musicians</dt>

<dd><a href="/artists/groups/">Group Acts</a></dd>

<dd>Solo Artists</dd>
<dd id="close_mnu">Close</dd>
</dl>
<dl id="artcat_3" class="open" onclick="openNav(this)">
<dt>Clubland &amp; Cabaret</dt>

<dd><a href="/artists/comedians/">Comedians</a></dd>
<dd id="close_mnu">Close</dd>
</dl>
<dl id="artcat_4" class="open" onclick="openNav(this)">
<dt>After  Dinner Speakers</dt>
<dd id="close_mnu">Close</dd>
</dl>
the close_mnu is not essential.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-07-2008, 07:49 PM Re: Looking for expanding & collapsing menu script
tonya's Avatar
Ultra Talker

Posts: 423
Location: world traveller based in UK
OK so to get your script to work I put it in script tags in head area of page & it applies to a definition list ?

which is type of ordered list ??

it kind of looks like an xml type list do I need a css sheet to go with it ??

sorry to act like a dumb arse - assume I know nothing & go from there - its been a long long time since I coded any javascript - about 8 years
__________________
Tonya

:: my personal site :: Marine Biology Site
tonya is offline
Reply With Quote
View Public Profile Visit tonya's homepage!
 
Old 09-07-2008, 07:49 PM Re: Looking for expanding & collapsing menu script
tonya's Avatar
Ultra Talker

Posts: 423
Location: world traveller based in UK
Thanks BTW !!!!
__________________
Tonya

:: my personal site :: Marine Biology Site
tonya is offline
Reply With Quote
View Public Profile Visit tonya's homepage!
 
Old 09-07-2008, 07:51 PM Re: Looking for expanding & collapsing menu script
tonya's Avatar
Ultra Talker

Posts: 423
Location: world traveller based in UK
WOW just seen it working on your site & its exactly what I was looking for

Now I just need to get it working for me LOL
__________________
Tonya

:: my personal site :: Marine Biology Site
tonya is offline
Reply With Quote
View Public Profile Visit tonya's homepage!
 
Old 09-07-2008, 08:22 PM Re: Looking for expanding & collapsing menu script
chrishirst's Avatar
Super Moderator

Posts: 15,313
Location: Blackpool. UK
this line var children = document.getElementsByTagName("DL"); change the DL to UL so it looks for an unordered list as the parent element

and I forgot to post the CSS because it uses a classname change to flip between open and closed.
Code:
#navigation dl.closed dd {
	display:none;
	visibility:hidden;
}
#navigation dl.open dd {
	display:block;
	visibility:visible;
}
recode the CSS to be a li inside a ul.classname
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System | Bits & Bobs

Last edited by chrishirst : 09-07-2008 at 08:23 PM.
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-07-2008, 08:36 PM Re: Looking for expanding & collapsing menu script
tonya's Avatar
Ultra Talker

Posts: 423
Location: world traveller based in UK
Its great script & I have worked out how to ammend it to my lists the only thing it does not do is remember the sub menu & so when you click on abba or the beatles I really want that submenu to stay open until you click a different choice like musicians
__________________
Tonya

:: my personal site :: Marine Biology Site
tonya is offline
Reply With Quote
View Public Profile Visit tonya's homepage!
 
Old 09-07-2008, 08:38 PM Re: Looking for expanding & collapsing menu script
tonya's Avatar
Ultra Talker

Posts: 423
Location: world traveller based in UK
Thanks for the post re lists - thats much appreciated & easier than me changing my list to a DL type lists

Can you get it to remember state - I am guessing thats what some scripts use a cookie for - so that in the sub menu it knows you are there
__________________
Tonya

:: my personal site :: Marine Biology Site
tonya is offline
Reply With Quote
View Public Profile Visit tonya's homepage!
 
Old 09-07-2008, 08:38 PM Re: Looking for expanding & collapsing menu script
tonya's Avatar
Ultra Talker

Posts: 423
Location: world traveller based in UK
I am dead close to simply cheating & having different script on each page to make it achieve same effect just not coded LOL
__________________
Tonya

:: my personal site :: Marine Biology Site
tonya is offline
Reply With Quote
View Public Profile Visit tonya's homepage!
 
Old 09-07-2008, 08:53 PM Re: Looking for expanding & collapsing menu script
chrishirst's Avatar
Super Moderator

Posts: 15,313
Location: Blackpool. UK
I actually use server side code to write a js script to set the appropriate category to open.

But a cookie would work just as well.

BTW always start with the menus OPEN, then hide them with js ( call closeAll() after the </body> tag) to make sure that visual non-js user agents can see the menu.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Looking for expanding & collapsing menu script
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.17370 seconds with 12 queries