-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdropmenu_09.html
More file actions
169 lines (137 loc) · 3.57 KB
/
dropmenu_09.html
File metadata and controls
169 lines (137 loc) · 3.57 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Drop Menu: Step 9</title>
<link rel="stylesheet" href="css/dropmenu.css">
<style type="text/css">
dl.drop-menu
{
position: absolute;
width: 160px;
left: 50%;
margin-top: 30px;
margin-left: -80px;
z-index: 1;
}
dl.drop-menu dt
{
padding: 0;
position: relative;
z-index: 1;
}
dl.drop-menu dd
{
padding: 0;
margin-top: -50px;
transition-property: margin-top;
transition-duration: 200ms;
transition-timing-function: ease-in;
}
dl.drop-menu dd.active
{
background: #ccb;
color: black;
}
dl.drop-menu dd.active a:focus
{
background: transparent;
}
dl.drop-menu:hover dd,
dl.drop-menu.open dd
{
margin-top: -1px;
transition-duration: 300ms;
transition-timing-function: ease-out;
}
dl.drop-menu a
{
display: inline-block;
width: inherit;
height: inherit;
padding: 15px 0;
text-decoration: none;
color: #c00;
}
dl.drop-menu a:focus
{
text-decoration: underline;
background: lightgoldenrodyellow;
}
dl.drop-menu a:active
{
background: #ccb;
}
dl.drop-menu dt a,
dl.drop-menu dt a:focus,
dl.drop-menu dt a:active
{
color: white;
background: #69c;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</head>
<body>
<nav>
<dl class="drop-menu">
<dt><a href="#null">Days of the Week</a></dt>
<dd><a href="#null">Monday</a></dd>
<dd><a href="#null">Tuesday</a></dd>
<dd><a href="#null">Wednesday</a></dd>
<dd><a href="#null">Thursday</a></dd>
<dd><a href="#null">Friday</a></dd>
<dd><a href="#null">Saturday</a></dd>
<dd><a href="#null">Sunday</a></dd>
</dl>
</nav>
<section>
<p>A CSS Drop Menu.</p>
</section>
<script>
/* DROP-CSS
*
* 1. There are many improvements to this code. Can you spot them all?
* 2. Does everything seem to make sense? Note especially the selectItem handler and where it is called.
* 3. At the bottom of the code are a few extensions to jQuery that provide special functionality.
* 4. What else could be done to improve it even further?
*
*/
var selectItem = function (event) {
$(event.target).closest("dd").addClass("active").siblings("dd").removeClass("active");
alert("It must be " + $(event.target).text());
};
$(".drop-menu").on("mouseover", function() {
$(this).find("dd:first a").focus();
$(".drop-menu").addClass("open").on("keyup", function (event) {
event.stopPropagation();
switch (event.keyCode) {
case 38:
$(event.target).closest("dd").prevOrLast("dd").find("a").focus();
break;
case 40:
$(event.target).closest("dd").nextOrFirst("dd").find("a").focus();
break;
case 13:
selectItem(event);
}
});
});
$(".drop-menu").on("mouseout", function() {
$(".drop-menu").removeClass("open").off("keyup");
});
$(".drop-menu").on("click", selectItem);
/* These are extensions to the jQuery language.
* These loop within a selection of sibling elements.
*/
$.fn.nextOrFirst = function(selector) {
var next = this.next(selector);
return (next.length) ? next : this.prevAll(selector).last();
};
$.fn.prevOrLast = function(selector) {
var prev = this.prev(selector);
return (prev.length) ? prev : this.nextAll(selector).last();
};
</script>
</body>
</html>