DanV
07-25-2005, 09:45 AM
I have never had a need to make an external stylesheet let alone an external js file until now when I'm working on a website. The need has come up to include a dhtml menu that has been offered free by its designer. I can get the effect if add all the code on each and every page but needless to say if it could be linked to one page that would save a lot of repetitive coding even with cut and paste.
I've tried to do this but somehow it's not working as it should. To my understanding thus far the section in red type is the sole thing that goes into the js file.
Then, again as I understand it, the second part of the menu, <div id="menu" class="menu">
<a href="http://whatever.com/contents.html" class="menuitem">contents</a>...and so forth with the other sections goes into the body of the webpage.
Then what I have read is that you place the following:<SCRIPT SRC="menu.js">
</SCRIPT> wherever you want it to appear on the webpage.
Sounds easy enough but easy seems to be on vacation when I try it.
The other question I ask myself is what do I do with .menu, .menuitem, and so on. I'm figuring I could make an external file for them but I'm already having difficulty as it is with one. Finally, there is the the menu itself (body) and I'm wondering if that has to go on every page.
I've looked all around the Net for instructions on this and the simplest instructions do not make it simple and the more elaborate ones, well, they might as well be talking Turkish.
Bottom line, I'm looking for a way to put the menu into an external file and then use it on each page of the website without having to go through the aforementioned repetition.
Any suggestions - perhaps on the level of the Sesame Street approach to javascript :-) - will be appreciated or even referred to a site where it's explained for beginners.
Thank You
_____________________________________________________
HTML
HEAD
TITLE>menu </TITLE
STYLE TYPE="text/css"
<style>
BODY { background-color: #000000 }
.menu { position: absolute;
width: 100px;
top: 0px;
left: 0px;
background-image: url(dscript107/back1.png);
visibility: hidden;
border: 1px solid;
border-color: #eeeeee #666666 #666666 #eeeeee;
padding: 2px;
z-index: 5;
filter: alpha(opacity=0);
-moz-opacity:1
}
.menuitem {
padding: 2px 4px 2px 4px;
color: #ffffff;
text-decoration: none;
font-family: ms sans serif;
font-size: 7px;
font-weight: normal;
display: block;
}
a.menuitem:hover {
color:lime;
background-color:gray;
background-image: url(dscript107/back.png);
}
</style>
<script type="text/javascript">
var ie5 = (document.getElementById&&document.all);
var n6 = (document.getElementById&&!document.all);
var x,y,el,pageW,pageH;
if (n6) document.addEventListener("mouseup",showMenu,false);
if (ie5) document.attachEvent("oncontextmenu",showMenu);
if (ie5) document.attachEvent("onclick",showMenu);
function showMenu(event) {
if (document.getElementById) {
pageW = document.body.offsetWidth;
pageH = document.body.offsetHeight;
x = event.clientX
y = event.clientY
el = document.getElementById("menu");
if ((ie5&&event.type=="contextmenu")||(n6 && event.which>1)) {
if ((x+parseInt(el.offsetWidth))>=pageW) {
x = parseInt(el.offsetWidth);
y = parseInt(el.offsetHeight);
}
el.style.top=y+"px";
el.style.left=x+"px";
fadeIn();
return false;
}
if ((ie5&&event.type=="click")||(n6 && event.which==1)) {
el.style.visibility="hidden";
fade_index = 0;
}
}
}
document.oncontextmenu=new Function("return false") ;
fade_index = 0;
function fadeIn() {
if(ie5 || n6) {
document.getElementById('menu').style.visibility = 'visible';
if(ie5) {
document.getElementById('menu').filters.alpha.opacity = fade_index;
}
if(n6) {
document.getElementById('menu').style.MozOpacity = fade_index/100;
}
fade_index += 3;
goIn = setTimeout("fadeIn()", 50);
if(fade_index >= 100)
clearTimeout(goIn);
}
}
</script>
</HEAD>
<BODY>
<!-- menu start -->
<div id="menu" class="menu">
<a href="http://whatever.com/contents.html" class="menuitem">contents</a>
<a href="http://whatever.com/instructions.html" class="menuitem">instructions</a>
<a href="http://whatever.com/introduction.html" class="menuitem">introduction</a>
I've tried to do this but somehow it's not working as it should. To my understanding thus far the section in red type is the sole thing that goes into the js file.
Then, again as I understand it, the second part of the menu, <div id="menu" class="menu">
<a href="http://whatever.com/contents.html" class="menuitem">contents</a>...and so forth with the other sections goes into the body of the webpage.
Then what I have read is that you place the following:<SCRIPT SRC="menu.js">
</SCRIPT> wherever you want it to appear on the webpage.
Sounds easy enough but easy seems to be on vacation when I try it.
The other question I ask myself is what do I do with .menu, .menuitem, and so on. I'm figuring I could make an external file for them but I'm already having difficulty as it is with one. Finally, there is the the menu itself (body) and I'm wondering if that has to go on every page.
I've looked all around the Net for instructions on this and the simplest instructions do not make it simple and the more elaborate ones, well, they might as well be talking Turkish.
Bottom line, I'm looking for a way to put the menu into an external file and then use it on each page of the website without having to go through the aforementioned repetition.
Any suggestions - perhaps on the level of the Sesame Street approach to javascript :-) - will be appreciated or even referred to a site where it's explained for beginners.
Thank You
_____________________________________________________
HTML
HEAD
TITLE>menu </TITLE
STYLE TYPE="text/css"
<style>
BODY { background-color: #000000 }
.menu { position: absolute;
width: 100px;
top: 0px;
left: 0px;
background-image: url(dscript107/back1.png);
visibility: hidden;
border: 1px solid;
border-color: #eeeeee #666666 #666666 #eeeeee;
padding: 2px;
z-index: 5;
filter: alpha(opacity=0);
-moz-opacity:1
}
.menuitem {
padding: 2px 4px 2px 4px;
color: #ffffff;
text-decoration: none;
font-family: ms sans serif;
font-size: 7px;
font-weight: normal;
display: block;
}
a.menuitem:hover {
color:lime;
background-color:gray;
background-image: url(dscript107/back.png);
}
</style>
<script type="text/javascript">
var ie5 = (document.getElementById&&document.all);
var n6 = (document.getElementById&&!document.all);
var x,y,el,pageW,pageH;
if (n6) document.addEventListener("mouseup",showMenu,false);
if (ie5) document.attachEvent("oncontextmenu",showMenu);
if (ie5) document.attachEvent("onclick",showMenu);
function showMenu(event) {
if (document.getElementById) {
pageW = document.body.offsetWidth;
pageH = document.body.offsetHeight;
x = event.clientX
y = event.clientY
el = document.getElementById("menu");
if ((ie5&&event.type=="contextmenu")||(n6 && event.which>1)) {
if ((x+parseInt(el.offsetWidth))>=pageW) {
x = parseInt(el.offsetWidth);
y = parseInt(el.offsetHeight);
}
el.style.top=y+"px";
el.style.left=x+"px";
fadeIn();
return false;
}
if ((ie5&&event.type=="click")||(n6 && event.which==1)) {
el.style.visibility="hidden";
fade_index = 0;
}
}
}
document.oncontextmenu=new Function("return false") ;
fade_index = 0;
function fadeIn() {
if(ie5 || n6) {
document.getElementById('menu').style.visibility = 'visible';
if(ie5) {
document.getElementById('menu').filters.alpha.opacity = fade_index;
}
if(n6) {
document.getElementById('menu').style.MozOpacity = fade_index/100;
}
fade_index += 3;
goIn = setTimeout("fadeIn()", 50);
if(fade_index >= 100)
clearTimeout(goIn);
}
}
</script>
</HEAD>
<BODY>
<!-- menu start -->
<div id="menu" class="menu">
<a href="http://whatever.com/contents.html" class="menuitem">contents</a>
<a href="http://whatever.com/instructions.html" class="menuitem">instructions</a>
<a href="http://whatever.com/introduction.html" class="menuitem">introduction</a>