Jump to content

Working with menus


KingOfHeart

Recommended Posts

I found this script online and while everything looks ok, for some reason the menu is not working.

 

<html>
<head>
<title>MyMenu</title>

<!--The CSS code.-->
<style type="text/css" media="screen">

#mymenu
{    margin: 0;
   padding: 0;
}

#mymenu li
{    margin: 0;
   padding: 0;
   list-style: none;
   float: left;
}

#mymenu li a
{    display: block;
   margin: 0 1px 0 0;
   padding: 4px 10px;
   width: 80px;
   background: #bbbaaa;
   color: #ffffff;
   text-align: center;
}

#mymenu li a:hover
{    background: #aaddaa}

#mymenu ul
{    position: absolute;
   visibility: hidden;
   margin: 0;
   padding: 0;
   background: #eeebdd;
   border: 1px solid #ffffff}

   #mymenu ul a
   {    position: relative;
    display: block;
    margin: 0;
    padding: 5px 10px;
    width: 80px;
    text-align: left;
    background: #eeebdd;
    color: #000000;
}

   #mymenu ul a:hover
   {    background: #aaffaa;
}
</style>
<!--The end of the CSS code.-->

<!--The Javascript menu code.-->
<script type="text/javascript">
//variables' declaration
var timer	    = 0;
var item	  = 0;

//function for opening of submenu elements
function openelement(num)
{    

//checks whether there is an open submenu and makes it invisible
if(item) item.style.visibility = 'hidden';

   //shows the chosen submenu element
   item = document.getElementById(num);
   item.style.visibility = 'visible';
}

// function for closing of submenu elements
function closeelement()
{
//closes the open submenu elements and loads the timer with 500ms
timer = window.setTimeout('if(item) item.style.visibility = 'hidden';',500);
}

//function for keeping the submenu loaded after the end of the 500 ms timer
function keepsubmenu()
{
    window.clearTimeout(timer);
}
//hides the visualized menu after clicking outside of its area and expiring of the loaded timer
document.onclick = closeelement;

</script>
<!--END of CSS code-->

</head>
<body>

<!--HTML code for the menu -->
<ul id="mymenu">
   <li><a href="http://siteground.com/">Home</a>
   </li>
   <li><a href="http://www.siteground.com/tutorials/" onmouseover="openelement('menu2')">Tutorials</a>
    <ul id="menu2" onmouseover="keepsubmenu()" onmouseout="closeelement()">
    <a href="http://www.siteground.com/tutorials/cssbasics/index.htm">CSS</a>
    <a href="http://www.siteground.com/tutorials/flash/index.htm">Flash</a>
    </ul>
   </li>
   <li><a href="#" onmouseover="openelement('menu3')" onmouseout="closeelement()">More</a>
    <ul id="menu3" onmouseover="keepsubmenu()" onmouseout="closeelement()">
    <a href="http://www.siteground.com/about_us.htm">About Us</a>
    <a href="http://www.siteground.com/contact_us.htm">Contact Us</a>
    </ul>
   </li>
</ul>
<div style="clear:both"></div>
<!--the end of the HTML code for the menu -->
</body>
</html>

 

http://king-trading.freeoda.com/TF2_quiz/trade_widow.html

----------------------------------

 

Also this entire fire can be turned into a javascript file, right? How do I call it in the body area?

Link to comment
Share on other sites

I hover over the menu with my mouse, all it does is highlight the main buttons. Nothing drops down so all I see is "home", "tutorials", and "more"

I don't see the rest. No CSS, no tutorial, no About us, and no contact us..

 

 

I'm still a newbie so can't really debug..all I plan on doing is changing link names, playing with the x/y, just taking it one step at a time and see how custom I can make it.

Link to comment
Share on other sites

I understand what the functions are suppose to do.

I haven't worked with it enough to just write my own script.

 

Answer me this, do you yourself see a major fault with the script?

If it's simple, just tell me please.

If it's complicated..well, I'll just google for more menu scripts and just fiddle with it.

Link to comment
Share on other sites

Your mark-up looks wrong as you have no list item tags in your sub unordered list tags.

 

If you can't be bothered understanding the script just use google to find another. Its a waste of everybodies time explaining what's wrong.

Link to comment
Share on other sites

You could also just learn jQuery and write one yourself. That way you will understand 100% of it, be able to edit and debug it, and you will know what to edit and what not to edit when it comes to making particular changes.

 

What I can do is have a go at making a small menu (like yours) myself with code that I will write, and post it here if I succeed and find its cross-browser compatible. Okay?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.