javascript-dropdown-menu
Gesponsorde koppelingen
PHP script bestanden
stylesheet.css
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
html, body, div, form
{
margin: 0px;
padding: 0px;
}
body
{
padding: 50px;
}
.dropdown
{
background: #000000;
height: auto;
padding: 4px 4px 4px 10px;
}
.dropdown ul
{
list-style: none none;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
text-align: left;
}
.dropdown ul li
{
display: inline;
margin: 0px 0px 0px 0px;
padding: 0px 18px 0px 0px;
position: relative;
}
.dropdown ul li a
{
color: #FFFFFF;
font-family: arial;
font-size: 12px;
font-weight: bold;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
text-decoration: none;
}
.dropdown ul li a:hover
{
text-decoration: underline;
}
.dropdown ul li ul
{
background: #F0F0F0;
border: #000000 solid 1px;
display: none;
left: 0px;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
position: absolute;
top: 25px;
}
.dropdown ul li ul li
{
color: #000000;
display: block;
font-family: Arial;
font-size: 12px;
font-weight: normal;
left: auto;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
text-align: left;
top: auto;
width: 120px;
}
.dropdown ul li ul li a
{
color: #000000;
display: block;
padding: 3px 3px 3px 6px;
}
.dropdown ul li ul li ul
{
left: 125px;
top: 2px;
}
{
margin: 0px;
padding: 0px;
}
body
{
padding: 50px;
}
.dropdown
{
background: #000000;
height: auto;
padding: 4px 4px 4px 10px;
}
.dropdown ul
{
list-style: none none;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
text-align: left;
}
.dropdown ul li
{
display: inline;
margin: 0px 0px 0px 0px;
padding: 0px 18px 0px 0px;
position: relative;
}
.dropdown ul li a
{
color: #FFFFFF;
font-family: arial;
font-size: 12px;
font-weight: bold;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
text-decoration: none;
}
.dropdown ul li a:hover
{
text-decoration: underline;
}
.dropdown ul li ul
{
background: #F0F0F0;
border: #000000 solid 1px;
display: none;
left: 0px;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
position: absolute;
top: 25px;
}
.dropdown ul li ul li
{
color: #000000;
display: block;
font-family: Arial;
font-size: 12px;
font-weight: normal;
left: auto;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
text-align: left;
top: auto;
width: 120px;
}
.dropdown ul li ul li a
{
color: #000000;
display: block;
padding: 3px 3px 3px 6px;
}
.dropdown ul li ul li ul
{
left: 125px;
top: 2px;
}
dropdown.js
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
var dropdown_rootNode = null; // Reference to root node of the current navigation.
var dropdown_timer = null; // Timer to hide all menu's on a 'onmouseout'.
var dropdown_timerWait = 750; // Time to wait before closing all open menu's.
var dropdown_zIndex = 1000; // zIndex of the navigation.
function createDropdown(nav_id)
{
if(document.getElementById) // Browser compatability
{
try
{
var rootNode = document.getElementById(nav_id);
// Add javascript to items in navigation and hide submenu's.
for(var i = 0; i < rootNode.childNodes.length; i++)
{
var ulNode = rootNode.childNodes[i];
if(ulNode.nodeName == 'UL') // Lookup UL tags
{
for(var j = 0; j < ulNode.childNodes.length; j++)
{
var liNode = ulNode.childNodes[j];
if(liNode.nodeName == 'LI') // Lookup LI tags
{
// Init subitems
__initDropdown(liNode);
// Add a mouseover-event to each list item.
liNode.onmouseover = function()
{
try
{
clearTimeout(dropdown_timer);
}
catch(e)
{
}
__showDropdown(this);
}
liNode.onmouseout = function()
{
try
{
clearTimeout(dropdown_timer);
}
catch(e)
{
}
dropdown_timer = setTimeout('__hideDropdown()', dropdown_timerWait);
}
}
}
}
}
}
catch(e)
{
// Ignore
}
}
}
// Add classes and mouse-events to subitems.
function __initDropdown(rootNode)
{
dropdown_zIndex += 2;
var zIndex = dropdown_zIndex;
// Open subitems
for(var i = 0; i < rootNode.childNodes.length; i++)
{
var ulNode = rootNode.childNodes[i];
if(ulNode.nodeName == 'UL')
{
ulNode.style.display = 'none';
ulNode.style.visibility = 'hidden';
ulNode.style.zIndex = zIndex;
for(var j = 0; j < ulNode.childNodes.length; j++)
{
var liNode = ulNode.childNodes[j];
if(liNode.nodeName == 'LI')
{
// liNode.style.zIndex = zIndex + 1;
// Init subitems
__initDropdown(liNode);
// Add a mouseover-event to each list item.
liNode.onmouseover = function()
{
try
{
clearTimeout(dropdown_timer);
}
catch(e)
{
}
this.className += ' hover';
__showDropdown(this);
}
liNode.onmouseout = function()
{
try
{
clearTimeout(dropdown_timer);
}
catch(e)
{
}
this.className = this.className.replace('hover', '');
dropdown_timer = setTimeout('__hideDropdown()', dropdown_timerWait);
}
}
}
}
}
}
// Show submenu
function __showDropdown(rootNode)
{
if(dropdown_rootNode == null)
{
dropdown_rootNode = rootNode.parentNode.parentNode;
}
// Hide siblings' submenu's
var ulNode = rootNode.parentNode;
for(var i = 0; i < ulNode.childNodes.length; i++)
{
var liNode = ulNode.childNodes[i];
if(liNode.nodeName == 'LI')
{
if(liNode != rootNode)
{
__hideDropdown(liNode);
}
}
}
// Show submenu's (if any)
for(var i = 0; i < rootNode.childNodes.length; i++)
{
var ulNode = rootNode.childNodes[i];
if(ulNode.nodeName == 'UL')
{
ulNode.style.display = 'block';
ulNode.style.visibility = 'visible';
}
}
}
// Hide submenu's
function __hideDropdown(rootNode)
{
if(__hideDropdown.arguments.length < 1)
{
var tmpNode = dropdown_rootNode;
dropdown_rootNode = null;
if(tmpNode != null)
{
for(var i = 0; i < tmpNode.childNodes.length; i++)
{
var ulNode = tmpNode.childNodes[i];
if(ulNode.nodeName == 'UL')
{
for(var j = 0; j < ulNode.childNodes.length; j++)
{
var liNode = ulNode.childNodes[j];
if(liNode.nodeName == 'LI')
{
__hideDropdown(liNode);
}
}
}
}
}
}
else
{
for(var i = 0; i < rootNode.childNodes.length; i++)
{
var ulNode = rootNode.childNodes[i];
if(ulNode.nodeName == 'UL')
{
ulNode.style.display = 'none';
ulNode.style.visibility = 'hidden';
for(var j = 0; j < ulNode.childNodes.length; j++)
{
var liNode = ulNode.childNodes[j];
if(liNode.nodeName == 'LI')
{
__hideDropdown(liNode);
}
}
}
}
}
}
var dropdown_timer = null; // Timer to hide all menu's on a 'onmouseout'.
var dropdown_timerWait = 750; // Time to wait before closing all open menu's.
var dropdown_zIndex = 1000; // zIndex of the navigation.
function createDropdown(nav_id)
{
if(document.getElementById) // Browser compatability
{
try
{
var rootNode = document.getElementById(nav_id);
// Add javascript to items in navigation and hide submenu's.
for(var i = 0; i < rootNode.childNodes.length; i++)
{
var ulNode = rootNode.childNodes[i];
if(ulNode.nodeName == 'UL') // Lookup UL tags
{
for(var j = 0; j < ulNode.childNodes.length; j++)
{
var liNode = ulNode.childNodes[j];
if(liNode.nodeName == 'LI') // Lookup LI tags
{
// Init subitems
__initDropdown(liNode);
// Add a mouseover-event to each list item.
liNode.onmouseover = function()
{
try
{
clearTimeout(dropdown_timer);
}
catch(e)
{
}
__showDropdown(this);
}
liNode.onmouseout = function()
{
try
{
clearTimeout(dropdown_timer);
}
catch(e)
{
}
dropdown_timer = setTimeout('__hideDropdown()', dropdown_timerWait);
}
}
}
}
}
}
catch(e)
{
// Ignore
}
}
}
// Add classes and mouse-events to subitems.
function __initDropdown(rootNode)
{
dropdown_zIndex += 2;
var zIndex = dropdown_zIndex;
// Open subitems
for(var i = 0; i < rootNode.childNodes.length; i++)
{
var ulNode = rootNode.childNodes[i];
if(ulNode.nodeName == 'UL')
{
ulNode.style.display = 'none';
ulNode.style.visibility = 'hidden';
ulNode.style.zIndex = zIndex;
for(var j = 0; j < ulNode.childNodes.length; j++)
{
var liNode = ulNode.childNodes[j];
if(liNode.nodeName == 'LI')
{
// liNode.style.zIndex = zIndex + 1;
// Init subitems
__initDropdown(liNode);
// Add a mouseover-event to each list item.
liNode.onmouseover = function()
{
try
{
clearTimeout(dropdown_timer);
}
catch(e)
{
}
this.className += ' hover';
__showDropdown(this);
}
liNode.onmouseout = function()
{
try
{
clearTimeout(dropdown_timer);
}
catch(e)
{
}
this.className = this.className.replace('hover', '');
dropdown_timer = setTimeout('__hideDropdown()', dropdown_timerWait);
}
}
}
}
}
}
// Show submenu
function __showDropdown(rootNode)
{
if(dropdown_rootNode == null)
{
dropdown_rootNode = rootNode.parentNode.parentNode;
}
// Hide siblings' submenu's
var ulNode = rootNode.parentNode;
for(var i = 0; i < ulNode.childNodes.length; i++)
{
var liNode = ulNode.childNodes[i];
if(liNode.nodeName == 'LI')
{
if(liNode != rootNode)
{
__hideDropdown(liNode);
}
}
}
// Show submenu's (if any)
for(var i = 0; i < rootNode.childNodes.length; i++)
{
var ulNode = rootNode.childNodes[i];
if(ulNode.nodeName == 'UL')
{
ulNode.style.display = 'block';
ulNode.style.visibility = 'visible';
}
}
}
// Hide submenu's
function __hideDropdown(rootNode)
{
if(__hideDropdown.arguments.length < 1)
{
var tmpNode = dropdown_rootNode;
dropdown_rootNode = null;
if(tmpNode != null)
{
for(var i = 0; i < tmpNode.childNodes.length; i++)
{
var ulNode = tmpNode.childNodes[i];
if(ulNode.nodeName == 'UL')
{
for(var j = 0; j < ulNode.childNodes.length; j++)
{
var liNode = ulNode.childNodes[j];
if(liNode.nodeName == 'LI')
{
__hideDropdown(liNode);
}
}
}
}
}
}
else
{
for(var i = 0; i < rootNode.childNodes.length; i++)
{
var ulNode = rootNode.childNodes[i];
if(ulNode.nodeName == 'UL')
{
ulNode.style.display = 'none';
ulNode.style.visibility = 'hidden';
for(var j = 0; j < ulNode.childNodes.length; j++)
{
var liNode = ulNode.childNodes[j];
if(liNode.nodeName == 'LI')
{
__hideDropdown(liNode);
}
}
}
}
}
}
index.html
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Dropdown Menu</title>
<link type="text/css" rel="stylesheet" href="./stylesheet.css" />
<script type="text/javascript" src="./dropdown.js"></script>
</head>
<body>
<div class="dropdown" id="my_dropdown_id">
<ul>
<li><a href="#">Item 1</a>
<ul>
<li><a href="#">Item 1.1</a>
<ul>
<li><a href="#">Item 1.1.1</a>
<ul>
<li><a href="#">Item 1.1.1.1</a>
<ul>
<li><a href="#">Item 1.1.1.1.1</a>
<ul>
<li><a href="#">Item 1.1.1.1.1.1</a></li>
<li><a href="#">Item 1.1.1.1.1.2</a></li>
<li><a href="#">Item 1.1.1.1.1.3</a></li>
<li><a href="#">Item 1.1.1.1.1.4</a></li>
<li><a href="#">Item 1.1.1.1.1.5</a></li>
</ul>
</li>
<li><a href="#">Item 1.1.1.1.2</a></li>
</ul>
</li>
<li><a href="#">Item 1.1.1.2</a></li>
<li><a href="#">Item 1.1.1.3</a></li>
<li><a href="#">Item 1.1.1.4</a></li>
</ul>
</li>
<li><a href="#">Item 1.1.2</a></li>
<li><a href="#">Item 1.1.3</a></li>
<li><a href="#">Item 1.1.4</a></li>
<li><a href="#">Item 1.1.5</a></li>
</ul>
</li>
<li><a href="#">Item 1.2</a></li>
</ul>
</li>
<li><a href="#">Item 2</a></li>
<li><a href="#">Item 3</a></li>
</ul>
</div>
<script type="text/javascript">
createDropdown('my_dropdown_id');
</script>
</body>
</html>
<html>
<head>
<title>Dropdown Menu</title>
<link type="text/css" rel="stylesheet" href="./stylesheet.css" />
<script type="text/javascript" src="./dropdown.js"></script>
</head>
<body>
<div class="dropdown" id="my_dropdown_id">
<ul>
<li><a href="#">Item 1</a>
<ul>
<li><a href="#">Item 1.1</a>
<ul>
<li><a href="#">Item 1.1.1</a>
<ul>
<li><a href="#">Item 1.1.1.1</a>
<ul>
<li><a href="#">Item 1.1.1.1.1</a>
<ul>
<li><a href="#">Item 1.1.1.1.1.1</a></li>
<li><a href="#">Item 1.1.1.1.1.2</a></li>
<li><a href="#">Item 1.1.1.1.1.3</a></li>
<li><a href="#">Item 1.1.1.1.1.4</a></li>
<li><a href="#">Item 1.1.1.1.1.5</a></li>
</ul>
</li>
<li><a href="#">Item 1.1.1.1.2</a></li>
</ul>
</li>
<li><a href="#">Item 1.1.1.2</a></li>
<li><a href="#">Item 1.1.1.3</a></li>
<li><a href="#">Item 1.1.1.4</a></li>
</ul>
</li>
<li><a href="#">Item 1.1.2</a></li>
<li><a href="#">Item 1.1.3</a></li>
<li><a href="#">Item 1.1.4</a></li>
<li><a href="#">Item 1.1.5</a></li>
</ul>
</li>
<li><a href="#">Item 1.2</a></li>
</ul>
</li>
<li><a href="#">Item 2</a></li>
<li><a href="#">Item 3</a></li>
</ul>
</div>
<script type="text/javascript">
createDropdown('my_dropdown_id');
</script>
</body>
</html>