The University of Washington Home Page, as well as other pages on www.washington.edu use DHTML and Javascript to implement "Flyout Menus". When the pointer passes over a link which has a menu, an image appears next to the item which leads to a box showing different options the user can select. If the mouse passes into another one of the links, the original menu disappears and the new one shows up. If the mouse passes completely out of the menu and the navigation area, then the menu will go away after a one second delay.
The source can be viewed in three ways:
If you wish to check the syntax of your Flyout Menus, you can do so with the Flyout Menu Tester. The Flyout Debugger tests your menus on your actual page.
The version document here is 2.9 from May, 2005. Thanks to Allen Olson who did the initial DOM support.
Instructions on use of the Flyout Menus are below. Also available are instructions for using the complex positioning methods, as well as methods for using predefined menus.
You are free to copy and/or use these flyout menus (or derivative works) but please make sure that the comment block at the top of the Javascript file remains intact and in its entirety.
Note that these menus were specifically designed with www.washington.edu in mind, but they should be adaptable to other sites, provided you supply a style sheet and change the defaults as per the Customizing section below. You may also want to investigate DHTML Lab's HierMenus for a different implementation, with different features.
This section explains what code needs to be added to a page to use Flyout Menus in the following link:
A simplified version of this example is available which shows the menus being implemented without the descriptive text, making it easier to see exactly what's involved in using the flyouts.If you are not using www.washington.edu, you will need to define a small amount of CSS. This example defines all links within barlink or navlink classes to have no underline decoration, as well as making barlink white in color (so it shows up against the dark blue title bar). The CSS can be viewed in the source of the example.
Developers on www.washington.edu can use the barlink and navlink classes which are already defined in the Home Page CSS file.
In the HEAD part of this page is a link to the Javascript file which is loaded. Note that this must appear between the <head> and </head> tags of the file.
<!--chtml include "//home/incs/flyout.inc"-->
This is a global chtml include file which contains the necessary Javascript to load the Flyout Menus program if the browser supports it, as well as optionally disabling flyouts. If you are not using chtml on www.washington.edu, the contents of that file are:
<script type="text/javascript">
<!--
function mIn () { return true; }
function mOut () { return true; }
function makeLayer () { return true; }
function flyDefs () { return true; }
if (! document.flyout_disable && 'undefined' != typeof document.getElementById)
document.write ('<' + 'script src="/home/scripts/flyout.js" ' +
'type="text/javascript"><' + "/script>\n");
// -->
</script>
If you are not on www.washington.edu at all, then you need to replace /home/scripts/flyout.js with a full URL: http://www.washington.edu/home/scripts/flyout.js
Note that what goes into the document head has a bit of code, but all the main definitions are actually in the file flyout.js. There are several workarounds in these few lines:
mIn () and mOut () would not get defined, causing errors. We therefore define stub functions in their place.makeLayer () and flyDefs () as dummy functions so the layer definition external files won't give errors.Within the body of the file comes the HTML to actually create the link:
<a href="#using" onmouseover="mIn ('menu1')"
onmouseout="mOut ('menu1')">Using Flyout Menus <img
src="/home/graphics/mo/noarrow.gif" width="6" height="11"
id="menu1" border="0" alt="" /></a>
Instead of spaces, is used to force everything onto one one line. This includes the image of the arrow which comes after the link text. The important additions are the id argument to the <img> tag and the onMouseOver and onMouseOut arguments to the <a> tag:
id="menu1"onMouseOver and onMouseOut arguments to the <a> tag, as well as the menu created in the script at the end of the file's <body> section.onMouseOver="mIn ('menu1')"onMouseOut="mOut ('menu1')"Last, at the end of the document's body is a link to script which actually build the menu:
<script src="menu1.js" language="Javascript1.2" type="text/javascript"></script>
The contents of the script are:
makeLayer ("menu1", "Using Flyout Menus=#using",
"CSS=#using-css",
"Main Script=#using-procs",
"Menu Creation=#using-creat",
" Tag Name=#using-creat-name",
" Title=#using-creat-title",
" Items=#using-creat-items",
"Link Definition=#using-link");
This code must appear after the code definition. Although it isn't required, it's advisable to require Javascript version 1.2 for this script. No harm is done to run it on older Javascript versions, but it will not have any effect. The notable exception is Netscape version 3, which will execute the script anyway.
The arguments to the makeLayer () function are the Tag ID, Title, and Items.
"menu1" argument associates the text link with the Flyout Menu and the arrow image, which are described below in the link definition.
The text supplied to the Title argument will appear as the title for the menu. In addition to the text "Using Flyout Menus" is a link definition, =#using, which causes the text to be an active link.
You can change the target of the link (for example, to open the link in another frame, or in a new window) by specifying the target at the end of the link with @. For example, if you wanted to link to a search engine in a new window, you would use:
"Search using Google=http://www.google.com/@_blank"
Some of the centrally-managed pages on www.washington.edu set the title of the Flyout Menus to be the same as the link which activates the menu, as well as making the title an active link which points to the same location. An example of this is shown from the UWIN page in the image on the right, with the purple-on-grey "Student Guide" being the link which triggers the Flyout, and the white-on-purple "Student Gude" being the title of the Flyout Menu (which is also a link and clickable). This is because some people don't realize that the link which triggers the Flyout is also active, so it gives them another opportunity to follow the main link in addition to the other links in the menu.
Some of the parameters for the Flyout Menus can be customized, as in this example. The text style has been changed, as has the color of the menu border and background. In addition, the Flyout Menu will stay for three seconds after the pointer is moved away, instead of staying for one second. Also, the image used has been changed.
The simplified version of this customizing example makes it easier to see just the components needed to do custom flyout menus.The main script is included the same way as in the previous example. However, note that this particular document only includes the script once, even though multiple menus (and even multiple kinds of menus) are defined.
Because we want the text of the menu to look different than the standard, a style sheet is created with those changes in mind:
<style type="text/css">
.menu2text {
font-family: "Times New Roman", Times, serif;
font-style: italic;
}
.menu2text a:link, .menu2text a:visited { text-decoration: none; }
</style>
The style sheet must come before the menu definition described in the next section. This is because the style must be defined before it is used in the creation of the Flyout Menu. The W3C has more information about how to use cascading style sheets.
As with the first example, the menus must be defined at the very end of the HTML body:
<script src="menu2.js" language="JavaScript1.2" type="text/javascript"></script>
The contents of this file look quite different from the previous example:
var newDefs = new Object;
newDefs.overimg = "redarrow.gif";
newDefs.background = "#cccccc";
newDefs.border = "#ff0000";
newDefs.useclass = "menu2text";
newDefs.timeout = 3000;
newDefs.pause = 100;
flyDefs (newDefs);
makeLayer ("menu2", "",
"Menu Script=#custom-procs",
"Style Definition=#custom-style",
"Menu Creation=#custom-creat",
"Link Definition=#custom-link",
"",
"Customization=#custom-cust",
" Image Definition=#custom-cust-img",
" Background and Border=#custom-cust-color",
" Text Class=#custom-cust-class",
" Timeout=#custom-cust-timeout"
);
The first set of lines which change the appearance of the menu will be described below. This menu has no title string, and therefore will have no title in the menu. The empty string between the two sections creates a dividing line in the menu.
Other than the different text, image, and tag ID, the link looks just like the previous example:
<a href="#custom" onMouseOver="mIn ('menu2')"
onMouseOut="mOut ('menu2')"
class="menu2text">Customizing Flyout Menus<img
src="noredarrow.gif" width="23" height="11" border="0"
id="menu2"></a>
The flydefs () function lets you change the appearance of the Flyout Menus. Notice that in addition to being enclosed with parentheses, the arguments to this function are also enclosed in braces, {}. The braces are the Javascript syntax to create an object, which is what flydefs expects. You only need to pass the parameters you wish to change from the defaults.
To change the arrow image, you should make sure to have a pair of images which are the same size. You should place the image in the HTML link, and define with flydefs the image which is used while a menu is active. In this example, the images are noredarrow.gif and redarrow.gif.
outimgnoredarrow.gif in this example. This same image is used as a placeholder in the HTML section. Normally, this image will be the same size as the arrow, but either a solid block the same color as the page background, or a completely transparent image. The default image is a solid white rectangle 6 pixels wide and 11 pixels high. If outimg is not defined, it will be the same as the original image on the page.overimgredarrow.gif in this example. The default image is a blue arrow pointing right, also 6 pixels wide by 11 pixels high.The background and border can subtly tie in the menu with the rest of your page. Be careful that the background does not conflict with any of the text colors you use (normal text, unselected links, and selected links.) Both of these parameters should use colors which are Web Safe and in the same format as used in style sheets.
border#ff0000, which is red. The default color is a dark blue, #333399.background#cccccc) is used by this example. The default is white, #ffffff.titlebackground#333399.These variables are used both for plain and link text in the Flyout Menu.
useclassmenu2text. The default is the navlink class. Developers who use the Home Page style sheet will already have navlink defined.titleclassbarlink class. Developers who use the Home Page style sheet will already have barlink defined.positionleftIf you wish to make the Flyout Menu to remain for shorter or longer than one second after the pointer moves out of the menu, the timeout variable can be used.
timeoutpausetimeout, this value should be in milliseconds. This example sets it to 100 (0.1 seconds.) The default value is 250 (0.25 seconds.)The Flyout Menus allow you to write Javascript which is called during certain operations.