File tree Expand file tree Collapse file tree 1 file changed +41
-1
lines changed Expand file tree Collapse file tree 1 file changed +41
-1
lines changed Original file line number Diff line number Diff line change 24
24
.panels {
25
25
min-height : 100vh ;
26
26
overflow : hidden;
27
+ display : flex;
27
28
}
28
29
29
30
.panel {
31
+ display : flex;
30
32
background : # 6B0F9C ;
31
33
box-shadow : inset 0 0 0 5px rgba (255 , 255 , 255 , 0.1 );
32
34
color : white;
41
43
font-size : 20px ;
42
44
background-size : cover;
43
45
background-position : center;
46
+ flex : 1 ;
47
+ flex-direction : column;
48
+ justify-content : center;
49
+ align-items : center;
44
50
}
45
51
46
52
53
59
.panel > * {
54
60
margin : 0 ;
55
61
width : 100% ;
56
- transition : transform 0.5s ;
62
+ transition : transform 0.5s ;
63
+ flex : 1 0 auto;
64
+ display : flex;
65
+ justify-content : center;
66
+ align-items : center;
67
+ }
68
+
69
+ .panel > * : first-child {
70
+ transform : translateY (-100% );
71
+ }
72
+
73
+ .panel .open-active > * : first-child {
74
+ transform : translateY (0 );
75
+ }
76
+
77
+ .panel > * : last-child {
78
+ transform : translateY (100% );
79
+ }
80
+
81
+ .panel .open-active > * : last-child {
82
+ transform : translateY (0 );
57
83
}
58
84
59
85
.panel p {
67
93
}
68
94
69
95
.panel .open {
96
+ flex : 5 ;
70
97
font-size : 40px ;
71
98
}
72
99
102
129
</ div >
103
130
104
131
< script >
132
+ const panels = document . querySelectorAll ( '.panel' )
133
+
134
+ function toggleOpen ( ) {
135
+ this . classList . toggle ( 'open' ) ;
136
+ }
137
+
138
+ function toggleActive ( e ) {
139
+ if ( e . propertyName . includes ( 'flex' ) ) {
140
+ this . classList . toggle ( 'open-active' )
141
+ }
142
+ }
105
143
144
+ panels . forEach ( panel => panel . addEventListener ( 'click' , toggleOpen ) ) ;
145
+ panels . forEach ( panel => panel . addEventListener ( 'transitionend' , toggleActive ) ) ;
106
146
</ script >
107
147
108
148
You can’t perform that action at this time.
0 commit comments