|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello there!
I had a question about a pull down menu script I found on the net. I was interested in formatting it slightly. THe menu basically runs off of three pages (menu.html, menu.css, and menu.js) This is what menu.js looks like: Code:
var menuTimeout = 300
var menuSections = new Array()
var menuCountHide = new Array()
var menuSectionCnt = 0
var menuBoxCnt = 0
function menuShow(section, elements) {
for (var i = 0; i < menuSections.length; i++) {
if (menuSections[i] != section) {
menuHide(menuSections[i], menuCountNodes(menuSections[i]))
}
}
for (var i = 1; i <= elements; i++) {
document.getElementById(section + '-' + i).style.visibility = 'visible'
}
}
function menuHide(section, elements) {
for (var i = 1; i <= elements; i++) {
document.getElementById(section + '-' + i).style.visibility = 'hidden'
document.getElementById(section).style.zIndex = -1
}
}
function menuTryHide(section, elements, countHide) {
if (countHide != menuCountHide[section]) {
return
}
menuHide(section, elements)
}
function menuCountNodes(element) {
ret = 0
nodes = document.getElementById(element).childNodes.length
for (var i = 0; i < nodes; i++) {
if (document.getElementById(element).childNodes[i].nodeType == 1) {
ret++
}
}
return ret
}
function menuInitSection(section) {
var elements = menuCountNodes(section)
for (var i = 0; i <= elements; i++) {
var s = (i == 0 ? (section + '-top') : (section + '-' + i))
if (i == 0) {
document.getElementById(s).onmouseover = function() {
menuShow(section, elements)
menuCountHide[section]++
for (var ii = 0; ii < menuSections.length; ii++) {
document.getElementById(section).style.zIndex = 1
if (menuSections[ii] != section) {
document.getElementById(menuSections[ii]).style.zIndex = -1
}
}
}
} else {
document.getElementById(s).onmouseover = function() {
menuShow(section, elements)
menuCountHide[section]++
}
}
document.getElementById(s).onmouseout = function() {
setTimeout("menuTryHide('" + section + "', " + elements + ", " + menuCountHide[section] + ")", menuTimeout)
}
}
}
function menuMakeId(nodes) {
for (var i = 0; i < nodes.length; i++) {
switch (nodes[i].className) {
case 'top':
menuSectionCnt++
menuBoxCnt = 0
nodes[i].id = 'menu-' + menuSectionCnt + '-top'
break
case 'section':
nodes[i].id = 'menu-' + menuSectionCnt
menuSections[menuSections.length] = nodes[i].id
break
case 'box':
menuBoxCnt++
nodes[i].id = 'menu-' + menuSectionCnt + '-' + menuBoxCnt
break
}
if (nodes[i].childNodes) {
menuMakeId(nodes[i].childNodes)
}
}
}
function menuInit() {
menuMakeId(document.getElementById('menu').childNo des)
for (var i = 0; i < menuSections.length; i++) {
menuCountHide[menuSections[i]] = 0
}
for (var i = 0; i < menuSections.length; i++) {
menuInitSection(menuSections[i])
}
}
Menu.css basically contains various text styles, and formats the background colours, etc (for the actual menu). The "text" for the category options and subcategories of the menu are embedded directly into menu.html. Basically, what I was interested in doing is INCREASING the HEIGHT of the menu, but I can't seem to figure out which page to edit, and how to go about doing this. Perhaps some of the more experienced javascript programmers may have an idea of what do do? If you would like to see the code for the other pages, let me know, and I'll put it in here. Your help would be GREATLY appreciated. And I would like to thank you in advance. |
|
#2
|
||||
|
||||
|
The CSS file would control all the presentational aspects of the menu. What you need to do is find the class or ID that controls the menu items. Without seeing the whole system, I'd guess the class is called "box".
|
|
#3
|
|||
|
|||
|
Hello!
Thanks for your quick response bud. The css style sheet looks like this, but it doesn't make sense to me as to where I would control the menu's height: Code:
#menu {
background : url(gradient.jpg);
}
#menu div.top {
padding-top: 5px;
padding-bottom: 6px;
padding-left: 6px;
padding-right: 8px;
width: 100%;
}
#menu div.section {
position: absolute;
display: inline;
z-index: -1;
}
#menu div.box {
background-color: #CACACA;
padding-top: 4px;
padding-bottom: 5px;
padding-left: 6px;
padding-right: 6px;
border-color: #ACACAC;
border-width: 1px;
border-style: none none solid none;
position: relative;
visibility: hidden;
width: 100%;
}
#menu a {
font-family: verdana;
font-size: 11px;
color: #464646;
text-decoration: none;
white-space: nowrap;
}
#menu a:hover {
font-family: verdana;
font-size: 11px;
color: #464646;
text-decoration: none;
white-space: nowrap;
}
|
|
#4
|
||||
|
||||
|
Try adding more padding to this rule: "#menu div.box". In fact, remove all their padding attributes and write this: "padding : 6px 6px;" - the first value is the top/bottom padding, the second is the left/right.
|
|
#5
|
|||
|
|||
|
ok - what should I REMOVE and what should I replace in the code? Sorry, I'm just trying to figure out what you would suggest I do (in order to increase the vertical thickness of this menu)
|
|
#6
|
||||
|
||||
|
To change the height of the item, add MORE PADDING to the top/bottom padding values.
|
|
#7
|
|||
|
|||
|
Thank you very much!
The only other small thing is that the increased height has caused the TEXT (for the main category options) to become top aligned. There's too much empty space near the bottom of the menu - Is there a way that I can "middle" align the text that shows up in the #menu div.top ? (I appreciate your help) |
|
#8
|
||||
|
||||
|
Can't really do much unless I can see the whole thing running. Can you put the code up somewhere live on the net?
|
|
#9
|
|||
|
|||
|
Absolutely!
http://www.dreamnation.ca/testing/menu/menu.html That's where the menu is located. As you can see the text for the menu's MAIN CATEGORIES, is at TOP aligned. I want it to be in the middle of the gradient (vertically speaking). |
|
#10
|
|||
|
|||
|
try posting the new css style sheet, with the changes on, opossed to the old one, and then let me take a look at it.
or you could give me the exact name of the css style, and i can take it down from your testsite my selvf, and post the changes. Just now, it lookes to me like, you have changed the wrong variables in the .css style - Pheifel |
|
#11
|
|||
|
|||
|
thanks - but I figured out a solution to my problem quite a while ago.
regards |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Javascript Pull Down Menu |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|