File tree 1 file changed +41
-0
lines changed
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 26
26
.panels {
27
27
min-height : 100vh ;
28
28
overflow : hidden;
29
+ display : flex;
29
30
}
30
31
31
32
.panel {
43
44
font-size : 20px ;
44
45
background-size : cover;
45
46
background-position : center;
47
+
48
+ flex : 1 ;
49
+ display : flex;
50
+ flex-direction : column;
51
+ justify-content : center;
52
+ align-items : center;
46
53
}
47
54
48
55
.panel1 { background-image : url (https://source.unsplash.com/gYl-UtwNg_I/1500x1500); }
56
63
margin : 0 ;
57
64
width : 100% ;
58
65
transition : transform 0.5s ;
66
+ flex : 1 0 auto;
67
+ display : flex;
68
+ justify-content : center;
69
+ align-items : center;
70
+ }
71
+
72
+ .panel > * : first-child {
73
+ transform : translateY (-100% );
74
+ }
75
+
76
+ .panel .open-active > * : first-child {
77
+ transform : translateY (0 );
78
+ }
79
+
80
+ .panel > * : last-child {
81
+ transform : translateY (100% );
82
+ }
83
+
84
+ .panel .open-active > * : last-child {
85
+ transform : translateY (0 );
59
86
}
60
87
61
88
.panel p {
71
98
72
99
.panel .open {
73
100
font-size : 40px ;
101
+ flex : 5 ;
74
102
}
75
103
76
104
</ style >
105
133
</ div >
106
134
107
135
< script >
136
+ const panels = document . querySelectorAll ( '.panel' ) ;
137
+
138
+ const toggleOpen = ( event , panel ) => {
139
+ panel . classList . toggle ( 'open' ) ;
140
+ }
141
+
142
+ const toggleActive = ( event , panel ) => {
143
+ if ( event . propertyName . includes ( 'flex' ) ) {
144
+ panel . classList . toggle ( 'open-active' ) ;
145
+ }
146
+ }
108
147
148
+ panels . forEach ( panel => panel . addEventListener ( 'click' , ( event ) => toggleOpen ( event , panel ) ) ) ;
149
+ panels . forEach ( panel => panel . addEventListener ( 'transitionend' , ( event ) => toggleActive ( event , panel ) ) ) ;
109
150
</ script >
110
151
111
152
You can’t perform that action at this time.
0 commit comments