-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson13_accordion.html
More file actions
162 lines (123 loc) · 3.5 KB
/
lesson13_accordion.html
File metadata and controls
162 lines (123 loc) · 3.5 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
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Getting Started wiht JAVA Script</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style>
body, .jumbotron {padding:30px;
}
body {
background: #EFEFEF;
}
html {
overflow-y: scroll;
}
.accordion {
background: #FFF;
border-radius: 5px;
padding: 30px;
}
.question {
border-top: 1px solid #EEE;
padding: 20px;
cursor: pointer;
position: relative;
}
.question h2 {
font-size: 20px;
margin: 0;
color: #C00C00;
}
.question .glyphicon {
position: absolute;
right: 20px;
top: 0;
height: 100%;
display: flex;
align-items: center;
transition: 0.5s linear;
}
.answer {
transition: 1s linear;
max-height: 0;
overflow: hidden;
}
.answer p{
padding: 20px;
}
.accordion li.open .answer {
max-height: 150px;
}
.accordion li.open .question .glyphicon {
transform: rotate(180deg);
}
ul {
margin-bottom: 0;
}
</style>
</head>
<body>
<div class="container">
<div class="accordion">
<ul class="list-unstyled">
<li class = "open">
<div class="question">
<h2>Will I be RICH?</h2>
<span class = "glyphicon glyphicon-chevron-down"></span>
</div>
<div class="answer">
<p>Absolutely! It's just a question of disire!
You need to change your maind in order to let himself
do the things that make your happy!</p>
</div>
</li>
<li>
<div class="question">
<h2>What's for dinner?</h2>
<span class = "glyphicon glyphicon-chevron-down"></span>
</div>
<div class="answer">
<p>Absolutely! It's just a question of disire!
You need to change your maind in order to let himself
do the things that make your happy!</p>
</div>
</li>
<li>
<div class="question">
<h2>Are youre learning JavaScript?</h2>
<span class = "glyphicon glyphicon-chevron-down"></span>
</div>
<div class="answer">
<p>Absolutely! It's just a question of disire!
You need to change your maind in order to let himself
do the things that make your happy!</p>
</div>
</li>
</ul>
</div>
</div>
<script>
//grab everything we need
const accordion = document.querySelector('.accordion');
const items = accordion.querySelectorAll('li');
const question = accordion.querySelectorAll('.question')
const answer = document.querySelectorAll('.answer')
//difine functions
function toggleAccordion(){
const thisItem = this.parentNode;
// console.log(this.parentNode);
items.forEach(item => {
if (thisItem == item) {
thisItem.classList.toggle('open');
return;
}
item.classList.remove('open');
});
}
//add event listeners
question.forEach(question => question.addEventListener('click', toggleAccordion));
answer.forEach(answer => answer.addEventListener ('click', toggleAccordion));
</script>
</body>
</html>