Simple Drop-down menu with Prototype
I worked on my friend Dylan Rhodes’ website called Reezle that just entered its public beta. Among other things I did the main navigation menu for the site. Since the website uses the Prototype-Scriptaculous combination it was logical to create this element with the existing libraries.
I eventually came up with a solution that was both elegant and efficient and I decided to release this script as open-source (with permission of course) as it can have many other implementations.
The above is included in the archive, along with the Prototype library, and I suggest you use that as a basis for your application. The actual JavaScript routine for the menu is this:
var DropDownMenu = Class.create(); DropDownMenu.prototype = { initialize: function(menuElement) { menuElement.childElements().each(function(node){ // if there is a submenu var submenu = $A(node.getElementsByTagName("ul")).first(); if(submenu != null){ // make sub-menu invisible Element.extend(submenu).setStyle({display: 'none'}); // toggle the visibility of the submenu node.onmouseover = node.onmouseout = function(){ Element.toggle(submenu); } } }); } };
Version: 1.0
Language: JavaScript
File size: 29,6kb
Last 5 projects by Makis
- Twitter Status v1.0 (with JSON and cURL in PHP) - December 2nd, 2009
- OptusZoo - Restructure - October 20th, 2009
- inSing.com: New website - May 18th, 2009
- Script: Post-load banner ads - May 17th, 2009
- Flash-antics: New website - May 6th, 2009
January 23rd, 2009 at 10:40 pm
This doesn’t quite work IE6, jus thought I’d let you know
January 24th, 2009 at 12:51 pm
Thanks Jonny,
That’s just fine – I think we can all live with the fact that IE6 is becoming obsolete, as you can see from the browser statistics:
http://www.w3schools.com/browsers/browsers_stats.asp
Give it another year and it will be the new IE5
August 6th, 2009 at 9:06 pm
Thank U