--------------------------- Javascript --------------------
function changeImg(img,w,h)
{
var ipath = "url(" + img + ")" ;
var hstring = h + 'px';
var wstring = w + 'px';
document.getElementById("mainContent").style.backgroundImage = ipath;
document.getElementById("mainContent").style.width = wstring;
document.getElementById("mainContent").style.height = hstring;
}
// JavaScript Document
/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Travis Beckham :: http://www.squidfingers.com | http://www.podlob.com
version date: 06/02/03 :: If want to use this code, feel free to do so,
but please leave this message intact. (Travis Beckham) */
// Node Functions
if(!window.Node){
var Node = {ELEMENT_NODE : 1, TEXT_NODE : 3};
}
function checkNode(node, filter){
return (filter == null || node.nodeType == Node[filter] || node.nodeName.toUpperCase() == filter.toUpperCase());
}
function getChildren(node, filter){
var result = new Array();
var children = node.childNodes;
for(var i = 0; i < children.length; i++){
if(checkNode(children[i], filter)) result[result.length] = children[i];
}
return result;
}
function getChildrenByElement(node){
return getChildren(node, "ELEMENT_NODE");
}
function getFirstChild(node, filter){
var child;
var children = node.childNodes;
for(var i = 0; i < children.length; i++){
child = children[i];
if(checkNode(child, filter)) return child;
}
return null;
}
function getFirstChildByText(node){
return getFirstChild(node, "TEXT_NODE");
}
function getNextSibling(node, filter){
for(var sibling = node.nextSibling; sibling != null; sibling = sibling.nextSibling){
if(checkNode(sibling, filter)) return sibling;
}
return null;
}
function getNextSiblingByElement(node){
return getNextSibling(node, "ELEMENT_NODE");
}
// Menu Functions & Properties
var activeMenu = null;
function showMenu() {
if(activeMenu){
activeMenu.className = "";
getNextSiblingByElement(activeMenu).style.display = "none";
}
if(this == activeMenu){
activeMenu = null;
} else {
this.className = "active";
getNextSiblingByElement(this).style.display = "block";
activeMenu = this;
}
return false;
}
function initMenu(){
var menus, menu, text, a, i;
menus = getChildrenByElement(document.getElementById("menu"));
for(i = 0; i < menus.length; i++){
menu = menus[i];
text = getFirstChildByText(menu);
a = document.createElement("a");
menu.replaceChild(a, text);
a.appendChild(text);
a.href = "#";
a.onclick = showMenu;
a.onfocus = function(){this.blur()};
}
}
if(document.createElement) window.onload = initMenu;
-------- end of Javascript -----
---------Beginning of CSS ------
@charset "utf-8";
body {
font:Arial, Helvetica, sans-serif;
font-size: 18px;
background: #CCC;
margin: 0;
padding: 0;
text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in
the #container selector */
color: #000000;
}
.twoColFixLt #container {
width: 1100px;
background: #FFFFFF;
margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
text-align: left; /* this overrides the text-align: center on the body element. */
}
.twoColFixLt #sidebar1 {
float: left; /* since this element is floated, a width must be given */
width: 300px;
padding: 15px 10px 15px 20px;
background: #39C;
}
.twoColFixLt #mainContent {
margin: 0 0 0 350px;
padding: 0 20px 20px;
padding-bottom: 10px;
position:relative;
background-repeat:no-repeat;
background-position: left top;
background-image:url(../DME/images/homepage.jpg);
width: 684px;
height: 684px;
}
.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should
be next to on the page. */
float: right;
margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page */
float: left;
margin-right: 8px;
}
.clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a
container that should fully contain a float */
clear:both;
height:0;
font-size: 1px;
line-height: 0px;
}
ul#menu {
width: 250px;
list-style-type: none;
border:none;
margin: 0;
padding: 0;
}
ul#menu ol {
display: none;
text-align: left;
list-style-type: none;
margin: 0;
padding-left: 12px;
padding-top: 3px;
padding-bottom: 3px;
padding-right: 0px;
}
ul#menu li,
ul#menu a {
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
font-weight:bold;
color:#000;
}
ul#menu li {
line-height: 30px;
}
ul#menu ol li {
border-bottom: none;
}
ul#menu ol li:before {
content: ">";
}
ul#menu a {
text-decoration: none;
outline: none;
}
ul#menu a:hover {
color: #FFF;
}
ul#menu a.active {
color:#FFF;
}
------------ end of CSS ------------------------
------------ beginning of HTML -------------------
<body class="twoColFixLt">
<div id="container">
<div id="header">
<h1 align="center">DME Guide</h1>
</div>
<div id="sidebar1">
<ul id="menu">
<li> Introduction
<ol>
<li> <a href="#" onclick="changeImg('images/introtext.jpg','684','684')">Overview</a> </li>
<li> <a href="#" onclick="changeImg('images/committee.jpg','684','792')">Rehab Standards Committee</a></li>
</ol>
</li>
<li>Assistive Technology
<ol>
<li> <a href="#">C1-3</a></li>
<li> <a href="#">C4</a></li>
<li> <a href="#">C5</a></li>
<li> <a href="#">C6-T1</a></li>
</ol>
</li>
<li>Bathing and Toileting
<ol>
<li> <a href="#">C1-4</a></li>
<li> <a href="#">C5-6</a></li>
<li> <a href="#">C7-T1</a></li>
<li> <a href="#">T2-T12</a></li>
<li> <a href="#">L1-S5</a></li>
</ol>
</li>
</ul>
<!-- end #sidebar1 --> </div>
<div id="mainContent">
</div>
<br class="clearfloat" />
<!-- end #container --></div>
</body>
</html>
function showMenu() {
if(activeMenu){
activeMenu.className = "";
getNextSiblingByElement(activeMenu).style.display = "none";
}
if(this == activeMenu){
activeMenu = null;
} else {
this.className = "active";
getNextSiblingByElement(this).style.display = "block";
activeMenu = this;
}
var liId = activeMenu.id;
var img;
switch(liId){
case "Intr":
img = "images/homepage.jpg";
break;
case "Assi":
img = "images/whatever.jpg";
break;
case "Bath":
img = "images/whatever.jpg";
break;
default:
img = "images/default.jpg";
}
document.getElementById('mainimage').src= img;
return false;
}
It works perfectly (as did the original script). If it is not working for you, let's investigate that. If you are losing the pointer and are unable to click, you likely have a syntax error in your javascript. It's the javascript that creates the links for the top level items. If they are not successfully converted to links, then there is an error.--------------------------- Javascript --------------------
function changeImg(img,w,h)
{
var ipath = "url(" + img + ")" ;
var hstring = h + 'px';
var wstring = w + 'px';
document.getElementById("mainContent").style.backgroundImage = ipath;
document.getElementById("mainContent").style.width = wstring;
document.getElementById("mainContent").style.height = hstring;
}
// JavaScript Document
/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Travis Beckham :: http://www.squidfingers.com | http://www.podlob.com
version date: 06/02/03 :: If want to use this code, feel free to do so,
but please leave this message intact. (Travis Beckham) */
// Node Functions
if(!window.Node){
var Node = {ELEMENT_NODE : 1, TEXT_NODE : 3};
}
function checkNode(node, filter){
return (filter == null || node.nodeType == Node[filter] || node.nodeName.toUpperCase() == filter.toUpperCase());
}
function getChildren(node, filter){
var result = new Array();
var children = node.childNodes;
for(var i = 0; i < children.length; i++){
if(checkNode(children[i], filter)) result[result.length] = children[i];
}
return result;
}
function getChildrenByElement(node){
return getChildren(node, "ELEMENT_NODE");
}
function getFirstChild(node, filter){
var child;
var children = node.childNodes;
for(var i = 0; i < children.length; i++){
child = children[i];
if(checkNode(child, filter)) return child;
}
return null;
}
function getFirstChildByText(node){
return getFirstChild(node, "TEXT_NODE");
}
function getNextSibling(node, filter){
for(var sibling = node.nextSibling; sibling != null; sibling = sibling.nextSibling){
if(checkNode(sibling, filter)) return sibling;
}
return null;
}
function getNextSiblingByElement(node){
return getNextSibling(node, "ELEMENT_NODE");
}
// Menu Functions & Properties
var activeMenu = null;
function showMenu() {
if(activeMenu){
document.getElementById('mainimage').src='images/homepage.jpg' ;
activeMenu.className = "";
getNextSiblingByElement(activeMenu).style.display = "none";
}
if(this == activeMenu){
activeMenu = null;
} else {
document.getElementById('mainimage').src='images/homepage.jpg';
this.className = "active";
getNextSiblingByElement(this).style.display = "block";
activeMenu = this;
}
return false;
}
function initMenu(){
var menus, menu, text, a, i;
menus = getChildrenByElement(document.getElementById("menu"));
for(i = 0; i < menus.length; i++){
menu = menus[i];
text = getFirstChildByText(menu);
a = document.createElement("a");
menu.replaceChild(a, text);
a.appendChild(text);
a.href = "#";
a.onclick = showMenu;
a.onfocus = function(){this.blur()};
}
}
if(document.createElement) window.onload = initMenu;
-------- end of Javascript -----
---------Beginning of CSS ------
@charset "utf-8";
body {
font:Arial, Helvetica, sans-serif;
font-size: 18px;
background: #CCC;
margin: 0;
padding: 0;
text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in
the #container selector */
color: #000000;
}
.twoColFixLt #container {
width: 1100px;
background: #FFFFFF;
margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
text-align: left; /* this overrides the text-align: center on the body element. */
}
.twoColFixLt #sidebar1 {
float: left; /* since this element is floated, a width must be given */
width: 300px;
padding: 15px 10px 15px 20px;
background: #39C;
}
.twoColFixLt #mainContent {
margin: 0 0 0 350px;
padding: 0 20px 20px;
padding-bottom: 10px;
position:relative;
}
.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should
be next to on the page. */
float: right;
margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page */
float: left;
margin-right: 8px;
}
.clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a
container that should fully contain a float */
clear:both;
height:0;
font-size: 1px;
line-height: 0px;
}
ul#menu {
width: 300px;
list-style-type: none;
border:none;
margin: 0;
padding: 0;
}
ul#menu ol {
display: none;
text-align: left;
list-style-type: none;
margin: 0;
padding-left: 12px;
padding-top: 3px;
padding-bottom: 3px;
padding-right: 0px;
}
ul#menu li,
ul#menu a {
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
font-weight:bold;
color:#000;
}
ul#menu li {
line-height: 30px;
}
ul#menu ol li {
border-bottom: none;
}
ul#menu ol li:before {
content: ">";
}
ul#menu a {
text-decoration: none;
outline: none;
}
ul#menu a:hover {
color: #FFF;
}
ul#menu a.active {
color:#FFF;
}
div#preload { display: none; }
------------ end of CSS ------------------------
------------ beginning of HTML -------------------
<body class="twoColFixLt">
<div id="container">
<div id="header">
<h1 align="center">DME Guide</h1>
</div>
<div id="sidebar1">
<ul id="menu">
<li id="li_intro"> Introduction
<ol>
<li> <a href="#" onclick="document.getElementById('mainimage').src='images/introtext.jpg'">Overview</a> </li>
<li> <a href="#" onclick="document.getElementById('mainimage').src='images/committee.jpg'">Rehab Standards Committee</a></li>
</ol>
</li>
<li id="li_assist">Assistive Technology
<ol>
<li> <a href="#">C1-3</a></li>
<li> <a href="#">C4</a></li>
<li> <a href="#">C5</a></li>
<li> <a href="#">C6-T1</a></li>
</ol>
</li>
<li id="li_bath">Bathing and Toileting
<ol>
<li> <a href="#">C1-4</a></li>
<li> <a href="#">C5-6</a></li>
<li> <a href="#">C7-T1</a></li>
<li> <a href="#">T2-T12</a></li>
<li> <a href="#">L1-S5</a></li>
</ol>
</li>
</ul>
<!-- end #sidebar1 --> </div>
<div id="mainContent">
<img src="images/homepage.jpg" name="mainimage" id="mainimage" border="0" align="left" />
</div>
<br class="clearfloat" />
<!-- end #container --></div>
<div id="preload">
<img src="images/homepage.jpg" />
<img src="images/introtext.jpg" />
<img src="images/committee.jpg" />
</div>
</body>
</html>
function showMenu() {
var liId;
var img;
if(activeMenu){
liId = activeMenu.id;
switch(liId) {
case "Intr":
img = "images/homepage.jpg";
break;
case "Assi":
img = "images/homepage.jpg";
break;
case "Bath":
img = "images/whatever.jpg";
break;
default:
img = "images/homepage.jpg";
}
document.getElementById('mainimage').src= img;
activeMenu.className = "";
getNextSiblingByElement(activeMenu).style.display = "none";
}
if(this == activeMenu){
activeMenu = null;
} else {
this.className = "active";
getNextSiblingByElement(this).style.display = "block";
activeMenu = this;
}
liId = activeMenu.id;
switch(liId) {
case "Intr":
img = "images/homepage.jpg";
break;
case "Assi":
img = "images/homepage.jpg";
break;
case "Bath":
img = "images/whatever.jpg";
break;
default:
img = "images/homepage.jpg";
}
document.getElementById('mainimage').src= img;
return false;
}
a.onmouseover = showmenu;
a.onmouseout = showmenu;
Then, menus would expand on hover (the more common behavior) instead of on click thus freeing up the onclick event for the image change.