-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtab.html
110 lines (89 loc) · 2.84 KB
/
tab.html
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
<!DOCTYPE html>
<head>
<title>tabs demo</title>
</head>
<style>
body {
font-family: Arial;
}
/* for tabs*/
.tab {
overflow: hidden;
background-color: #f2f3f4;
border: 1px solid #ddd;
}
.tab button {
float: left;
background-color: inherit;
border: none;
font-size: 18px;
padding: 14px 16px;
}
.tab button:hover {
background-color: #ccc;
}
.tab button.active {
background-color: #bbb;
}
/* for tabcontent*/
.tabcontent {
border: 1px solid #ddd;
border-top: none;
padding: 8px 16px;
animation: fadeEffect 2s;
}
@keyframes fadeEffect {
from {opacity: 0;}
to {opacity: 1;}
}
/* for close button*/
.topright {
float: right;
font-size: 24px;
cursor: pointer;
}
</style>
<body>
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')">London</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
</div>
<div id="London" class="tabcontent">
<span class="topright" onclick="this.parentElement.style.display = 'none';">×</span>
<h3>London</h3>
<p>London is the capital city of England</p>
</div>
<div id="Paris" class="tabcontent">
<span class="topright" onclick="this.parentElement.style.display = 'none';">×</span>
<h3>Paris</h3>
<p>Paris is the capital city of France</p>
</div>
<div id="Tokyo" class="tabcontent">
<span class="topright" onclick="this.parentElement.style.display = 'none';">×</span>
<h3>Tokyo</h3>
<p>Tokyo is the capital city of Japan</p>
</div>
<script>
function openCity(evt, cityName) {
// 1. hide all the tabcontent -- set all the tabcontent to display:none
var tabContents = document.getElementsByClassName("tabcontent");
for(var i=0; i<tabContents.length; i++) {
tabContents[i].style.display = "none";
}
// 2. lowhight all the tabs - -remove the class " active" from all the tab className
var tabs = document.getElementsByClassName("tablinks");
for(var i=0; i<tabs.length; i++) {
tabs[i].className = tabs[i].className.replace(' active', '');
// console.log(tabs[i].className);
}
// 3. highlight the current tab -- add " active" to the current tab
//????
evt.currentTarget.className += ' active';
// 4. display the tabcontent for the current tab
document.getElementById(cityName).style.display = 'block';
}
// show the tabcontent for the first tab as default
document.getElementsByClassName("tablinks")[0].click();
</script>
</body>