|
||||
JavaScripting Workbook 2 AnswersNice work on the workbooks, all! Here are some answers from a mix of students in class... Extending the basic Netscape Rollover ApproachWe looked at a simple example of using the onmouseover and onmouseout attributes of the Anchor element (the A element) to provide a visual rollover effect. <HTML> <HEAD> <TITLE>Basic JavaScript Rollover by Joe Maller</TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- hide from non JavaScript Browsers Rollimage = new Array(); Rollimage[0]= new Image(121,153); Rollimage[0].src = "joe_open.jpg"; Rollimage[1] = new Image(121,153); Rollimage[1].src = "joe_blink.jpg"; Rollimage[2] = new Image(121,153); Rollimage[2].src = "joe_tongue.jpg"; function SwapOut(){ document.Rupert.src = Rollimage[1].src; return true; } function SwapBack(){ document.Rupert.src = Rollimage[0].src; return true; } function StickOut(){ document.Rupert.src = Rollimage[2].src; return true; } // - stop hiding --> </SCRIPT> </HEAD> <BODY BGCOLOR="#FFFFFF"> <P align="center"> <A HREF="#" onmouseover="SwapOut()" onmouseout="SwapBack()" onclick="StickOut()"> <IMG SRC="joe_open.jpg" NAME="Rupert" WIDTH=121 HEIGHT=153 BORDER=0> </A> <P align="center">If you use this, please give Joe credit.</P> </BODY> </HTML>To use an DIV element instead of the A element, check out a composite student solution. Practicing the CSS rollover techniqueAdd a second rollover image to start the process of creating a menu from CSS rollover components. Code provided by Dennis Bell's example: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- #rollover a { display:block; width:50px; background-color: #FFFFFF} #rollover a:hover { background-color: #990000} #rollover2 a { display:block; width:50px; background-color: #03F} #rollover2 a:hover { background-color: #0F9} --> </style> </head> <body bgcolor="222222"> <div id="rollover"> <p> <a href="#"><img src="d.gif" width="50" height="50" border="0"></a> </p> </div> <div id="rollover2"> <p> <a href="#"><img src="b.gif" width="50" height="50" border="0"></a> </p> </div> </body> </html>
Altering Autogenerated codeChanging the code so that the description of each menu item appears to the right of the menu instead of as a separate menu table item beneath the menu options.
from following code (available here): <html> function moveout(which) { --> which, upon making appropriate changes based on best practices we studied in class, creates this page here. |
||||