Skip to content

Commit 6e5c3cb

Browse files
committed
Finished Chapter 16 Exercise 1
1 parent 482adce commit 6e5c3cb

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

ch16exercise1.html

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Chapter 16: Exercise 1</title>
5+
<style>
6+
.tabStrip {
7+
background-color: #E4E2D5;
8+
padding: 3px;
9+
height: 22px;
10+
}
11+
.tabStrip div {
12+
float: left;
13+
font: 14px arial;
14+
cursor: pointer;
15+
}
16+
.tabStrip-tab {
17+
padding: 3px;
18+
}
19+
.tabStrip-tab-hover {
20+
border: 1px solid #316AC5;
21+
background-color: #C1D2EE;
22+
padding: 2px;
23+
}
24+
.tabStrip-tab-click {
25+
border: 1px solid #facc5a;
26+
background-color: #f9e391;
27+
padding: 2px;
28+
}
29+
</style>
30+
</head>
31+
<body>
32+
<div class="tabStrip">
33+
<div data-tab-number="1" class="tabStrip-tab">Tab 1</div>
34+
<div data-tab-number="2" class="tabStrip-tab">Tab 2</div>
35+
<div data-tab-number="3" class="tabStrip-tab">Tab 3</div>
36+
</div>
37+
<div id="descContainer"></div>
38+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
39+
<script>
40+
function handleEvent(e) {
41+
var target = $(e.target);
42+
var type = e.type;
43+
if (type == "mouseover" || type == "mouseout") {
44+
target.toggleClass("tabStrip-tab-hover");
45+
} else if (type == "click") {
46+
$(".tabStrip-tab").removeClass("tabStrip-tab-click");
47+
target.addClass("tabStrip-tab-click");
48+
var num = target.attr("data-tab-number");
49+
showDescription(num);
50+
}
51+
}
52+
function showDescription(num) {
53+
var text = "Description for Tab " + num;
54+
$("#descContainer").text(text);
55+
}
56+
$(".tabStrip > div").on("mouseover mouseout click", handleEvent);
57+
</script>
58+
</body>
59+
</html>

0 commit comments

Comments
 (0)