質問編集履歴
1
SCSSをCSSへ変更しました。アコーディオン 機能の定義を追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,9 +10,17 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
+
追記
|
14
|
+
|
15
|
+
※アコーディオン は、<H4 class="js_accordion_title">をクリックすると、.accordion_contentが開く。
|
16
|
+
|
17
|
+
再度、js_accordion_titleをクリックすると開いている.accordion_contentが閉じる というものです。
|
18
|
+
|
19
|
+
|
20
|
+
|
13
|
-
|
21
|
+
このままでは開きもしませんし、閉じもしません。
|
14
|
-
|
15
|
-
|
22
|
+
|
23
|
+
|
16
24
|
|
17
25
|
|
18
26
|
|
@@ -102,35 +110,41 @@
|
|
102
110
|
|
103
111
|
```
|
104
112
|
|
105
|
-
```
|
113
|
+
```CSS
|
106
114
|
|
107
115
|
@charset "UTF-8";
|
108
116
|
|
109
117
|
|
110
118
|
|
111
|
-
|
119
|
+
*{
|
112
|
-
|
120
|
+
|
113
|
-
margin:0;
|
121
|
+
margin: 0;
|
114
|
-
|
122
|
+
|
115
|
-
padding:0;
|
123
|
+
padding: 0;
|
116
|
-
|
124
|
+
|
117
|
-
}
|
125
|
+
}
|
118
|
-
|
126
|
+
|
127
|
+
|
128
|
+
|
119
|
-
.accordion{
|
129
|
+
.accordion{
|
120
|
-
|
130
|
+
|
121
|
-
margin-top:10px;
|
131
|
+
margin-top: 10px;
|
122
|
-
|
132
|
+
|
123
|
-
}
|
133
|
+
}
|
124
|
-
|
134
|
+
|
135
|
+
|
136
|
+
|
125
|
-
.accordion_container{
|
137
|
+
.accordion_container {
|
126
|
-
|
138
|
+
|
127
|
-
width:300px;
|
139
|
+
width: 300px;
|
128
|
-
|
140
|
+
|
129
|
-
margin:0 auto;
|
141
|
+
margin: 0 auto;
|
130
|
-
|
142
|
+
|
131
|
-
}
|
143
|
+
}
|
132
|
-
|
144
|
+
|
145
|
+
|
146
|
+
|
133
|
-
.accordion_title{
|
147
|
+
.accordion_title {
|
134
148
|
|
135
149
|
background-color: #000;
|
136
150
|
|
@@ -148,122 +162,134 @@
|
|
148
162
|
|
149
163
|
user-select: none;
|
150
164
|
|
151
|
-
|
165
|
+
}
|
152
|
-
|
166
|
+
|
167
|
+
|
168
|
+
|
153
|
-
|
169
|
+
.accordion_title::before, .accordion_title::after {
|
154
|
-
|
170
|
+
|
155
|
-
|
171
|
+
content: '';
|
156
|
-
|
172
|
+
|
157
|
-
|
173
|
+
display: block;
|
158
|
-
|
174
|
+
|
159
|
-
|
175
|
+
background-color: #fff;
|
160
|
-
|
176
|
+
|
161
|
-
|
177
|
+
position: absolute;
|
162
|
-
|
178
|
+
|
163
|
-
|
179
|
+
top: 50%;
|
164
|
-
|
180
|
+
|
165
|
-
|
181
|
+
width: 15px;
|
166
|
-
|
182
|
+
|
167
|
-
|
183
|
+
height: 2px;
|
168
|
-
|
184
|
+
|
169
|
-
|
185
|
+
right: 25px;
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
.accordion_title::after {
|
192
|
+
|
193
|
+
transform: rotate(90deg);
|
194
|
+
|
195
|
+
transition-duration: .3s;
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
.accordion_title:hover,
|
202
|
+
|
203
|
+
.accordion_title:active,
|
204
|
+
|
205
|
+
.accordion_title.is-active {
|
206
|
+
|
207
|
+
background-color: #00aaa7;
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
.accordion_title.is-active::before {
|
214
|
+
|
215
|
+
opacity: 0;
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
.accordion_title.is-active::after {
|
222
|
+
|
223
|
+
transform: rotate(0);
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
.accordion_content {
|
230
|
+
|
231
|
+
border-left: 1px solid transparent;
|
232
|
+
|
233
|
+
border-right: 1px solid transparent;
|
234
|
+
|
235
|
+
padding: 0 1.5em;
|
236
|
+
|
237
|
+
line-height: 0;
|
238
|
+
|
239
|
+
height: 0;
|
240
|
+
|
241
|
+
overflow: hidden;
|
242
|
+
|
243
|
+
opacity: 0;
|
244
|
+
|
245
|
+
transition-duration: .3s;
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
.accordion_content.is-open {
|
252
|
+
|
253
|
+
border: 1px solid #00aaa7;
|
254
|
+
|
255
|
+
padding: .625em 1.5em;
|
256
|
+
|
257
|
+
line-height: normal; /* numberに書き換える*/
|
258
|
+
|
259
|
+
height: auto;
|
260
|
+
|
261
|
+
opacity: 1;
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
```
|
266
|
+
|
267
|
+
```javascript
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
document.addEventListener("DOMContentLoaded",() => {
|
272
|
+
|
273
|
+
const title = document.querySelectorAll('.js-accordion-title');
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
for (let i = 0; i < title.length; i++){
|
278
|
+
|
279
|
+
let titleEach = title[i];
|
280
|
+
|
281
|
+
let content = titleEach.nextElementSibling;
|
282
|
+
|
283
|
+
titleEach.addEventListener('click', () => {
|
284
|
+
|
285
|
+
titleEach.classList.toggle('is-active');
|
286
|
+
|
287
|
+
content.classList.toggle('is-open');
|
288
|
+
|
289
|
+
});
|
170
290
|
|
171
291
|
}
|
172
292
|
|
173
|
-
&::after{
|
174
|
-
|
175
|
-
transform: rotate(90deg);
|
176
|
-
|
177
|
-
transition-duration: .3s;
|
178
|
-
|
179
|
-
}
|
180
|
-
|
181
|
-
&:hover,.active,.is-active{
|
182
|
-
|
183
|
-
background-color: #00aaa7;
|
184
|
-
|
185
|
-
}
|
186
|
-
|
187
|
-
.is-active{
|
188
|
-
|
189
|
-
&::before{
|
190
|
-
|
191
|
-
opacity:0;
|
192
|
-
|
193
|
-
}
|
194
|
-
|
195
|
-
&::after{
|
196
|
-
|
197
|
-
transform:rolate(0);
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
}
|
202
|
-
|
203
|
-
}
|
204
|
-
|
205
|
-
.accordion_content{
|
206
|
-
|
207
|
-
border-left: 1px solid transparent;
|
208
|
-
|
209
|
-
border-right: 1px solid transparent;
|
210
|
-
|
211
|
-
padding: 0 1.5em;
|
212
|
-
|
213
|
-
line-height: 0;
|
214
|
-
|
215
|
-
height: 0;
|
216
|
-
|
217
|
-
overflow: hidden;
|
218
|
-
|
219
|
-
opacity: 0;
|
220
|
-
|
221
|
-
transition-duration: .3s;
|
222
|
-
|
223
|
-
}
|
224
|
-
|
225
|
-
.accordion__content.is-open {
|
226
|
-
|
227
|
-
border: 1px solid #00aaa7;
|
228
|
-
|
229
|
-
padding: .625em 1.5em;
|
230
|
-
|
231
|
-
line-height: normal; /* numberに書き換える*/
|
232
|
-
|
233
|
-
height: auto;
|
234
|
-
|
235
|
-
opacity: 1;
|
236
|
-
|
237
|
-
}
|
238
|
-
|
239
|
-
```
|
240
|
-
|
241
|
-
```javascript
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
document.addEventListener("DOMContentLoaded",() => {
|
246
|
-
|
247
|
-
const title = document.querySelectorAll('.js-accordion-title');
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
for (let i = 0; i < title.length; i++){
|
252
|
-
|
253
|
-
let titleEach = title[i];
|
254
|
-
|
255
|
-
let content = titleEach.nextElementSibling;
|
256
|
-
|
257
|
-
titleEach.addEventListener('click', () => {
|
258
|
-
|
259
|
-
titleEach.classList.toggle('is-active');
|
260
|
-
|
261
|
-
content.classList.toggle('is-open');
|
262
|
-
|
263
|
-
});
|
264
|
-
|
265
|
-
}
|
266
|
-
|
267
293
|
|
268
294
|
|
269
295
|
});
|