回答編集履歴

1

同じ要素をクリックしたときに閉じるという動作を加えました。

2020/11/04 12:44

投稿

rei02
rei02

スコア1

test CHANGED
@@ -2,36 +2,36 @@
2
2
 
3
3
 
4
4
 
5
- function toggleOpen(){
5
+ function toggleOpen() {
6
6
 
7
- panels.forEach(function(panel){
7
+ panels.forEach(panel => panel.classList.remove("open"));
8
8
 
9
- panel.addEventListener("click", function(){
9
+ this.classList.add("open");
10
10
 
11
-
11
+ if(this.classList.contains("open-active")){
12
12
 
13
- panel.classList.toggle("open");
13
+ this.classList.remove("open");
14
14
 
15
- });
15
+ }
16
16
 
17
-
18
-
19
- });
20
-
21
- };
17
+ };
22
18
 
23
19
 
24
20
 
25
- function toggleActive(e){
26
21
 
27
- if(e.propertyName.includes('flex-grow')){
28
22
 
29
- this.classList.toggle('open-active');
23
+ function toggleActive(e){
30
24
 
31
- }
25
+ if(e.propertyName.includes('flex-grow')){
32
26
 
33
- }
27
+ this.classList.toggle("open-active");
34
28
 
35
- panels.forEach(panel => panel.addEventListener('transitionend', toggleActive));
29
+ }
36
30
 
31
+ }
32
+
33
+
34
+
37
- toggleOpen();
35
+ panels.forEach(panel => panel.addEventListener('click', toggleOpen));
36
+
37
+ panels.forEach(panel => panel.addEventListener('transitionend', toggleActive));