Back in my freshman year of college I created this website for my html class: http://web.ics.purdue.edu/~jmabrito/
4 years later, I am creating a new website and want to use that CSS/Javascript menu from that website. However, I am having a hard time understanding the CSS and Javascript code I used back then.
Here is the CSS code I used:
The part I am getting confused at in the CSS code is the .menu a {} attribute and all the values I used in it. Specifically why did I choose 137px and 130px. I know it has something to do with the total length of the menu being 700px.
Here is the Javascript code I used:
I understand the javascript part except the var sub1 - var sub 4 variables and the pixel lengths I assigned to the offsetleftvalue variable. It has something to do with 137px I set in the CSS page.
Can anyone help fill in these mental gaps?
4 years later, I am creating a new website and want to use that CSS/Javascript menu from that website. However, I am having a hard time understanding the CSS and Javascript code I used back then.
Here is the CSS code I used:
Code:
body {margin: 5 padding: 0;}
div {font: 10px verdana,geneva,lucida,arial,sans-serif;}
.menu {visibility: hidden;}
#start {visibility: visible; width: 700px;
margin-left: auto; margin-right: auto;}
#story, #characters, #review, #support {position: absolute; top: 228px;}
#start a {float: left;}
.menu a.over {background: #000; color: #fff;}
.menu a {width: 137px; text-decoration: none;
padding: 5px 0 5px 5px; color: #000; letter-spacing: 1px;
border: 1px solid #fff; background: #ddd; display: block;
voice-family: "\"}\""; voice-family:inherit; width: 130px;}
The part I am getting confused at in the CSS code is the .menu a {} attribute and all the values I used in it. Specifically why did I choose 137px and 130px. I know it has something to do with the total length of the menu being 700px.
Here is the Javascript code I used:
Code:
var W3CDOM = document.getElementById;
var openMenus = new Array();
var pressedNav = new Array();
var subMenus = new Array();
var timer, browser;
var ua = navigator.userAgent.toLowerCase();
subMenus[1] = 'story';
subMenus[2] = 'characters';
subMenus[3] = 'review';
subMenus[4] = 'support';
function getObj(idvalue) {
return document.getElementById(idvalue);
}
function getObjStyle(idvalue) {
return document.getElementById(idvalue).style;
}
function setTimer() {
if (timer) clearTimeout(timer);
timer = setTimeout('closeAllMenus(1)',20);
}
function display() {
if (timer) clearTimeout(timer);
var num = this.number;
if (num <= 4) menuLvl = 1;
if (num > 4) menuLvl = 2;
if (openMenus[menuLvl] && openMenus[menuLvl] == subMenus[num]) return;
if (openMenus[menuLvl]) closeAllMenus(menuLvl);
if (!subMenus[num]) {}
else {
menuToShow = getObjStyle(subMenus[num]);
menuToShow.visibility = 'visible';
}
openMenus[menuLvl] = subMenus[num];
if (this.className) return;
this.className = 'over';
if (pressedNav[menuLvl]) pressedNav[menuLvl].className = '';
pressedNav[menuLvl] = this;
}
function closeAllMenus(lvl) {
for (i=openMenus.length - 1; i>=lvl; i--) {
if (openMenus[i]) {
menuToHide = getObjStyle(openMenus[i]);
menuToHide.visibility = 'hidden';
}
openMenus[i] = null;
if (pressedNav[i]) {
pressedNav[i].className = '';
pressedNav[i] = null;
}
}
}
function detect(text) {
stringposition = ua.indexOf(text) + 1;
data = text;
return stringposition;
}
if ((detect('msie 5.01')) && (detect('win')) || (detect('safari'))) {
browser = "adjust";
}
function detectLocations() {
var offsetLeftValue = 0;
navItems[0].style.position = 'relative';
offsetLeftValue += navItems[0].offsetLeft;
var sub1 = getObjStyle('story');
if (browser == 'adjust') sub1.left = offsetLeftValue + 142 + 'px';
else sub1.left = offsetLeftValue + 137 + 'px';
var sub2 = getObjStyle('characters');
if (browser == 'adjust') sub2.left = offsetLeftValue + 279 + 'px';
else sub2.left = offsetLeftValue + 274 + 'px';
var sub3 = getObjStyle('review');
if (browser == 'adjust') sub3.left = offsetLeftValue + 416 + 'px';
else sub3.left = offsetLeftValue + 411 + 'px';
var sub4 = getObjStyle('support');
if (browser == 'adjust') sub4.left = offsetLeftValue + 553 + 'px';
else sub4.left = offsetLeftValue + 548 + 'px';
}
window.onload = function() {
if (!W3CDOM) return;
navHolder = getObj('navbar');
navItems = navHolder.getElementsByTagName('a');
detectLocations();
for (i=0; i<navItems.length; i++) {
navItems[i].onmouseover = display;
navItems[i].onmouseout = setTimer;
navItems[i].number = i;
}
}
window.onresize = detectLocations;
I understand the javascript part except the var sub1 - var sub 4 variables and the pixel lengths I assigned to the offsetleftvalue variable. It has something to do with 137px I set in the CSS page.
Can anyone help fill in these mental gaps?