File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424 .panels {
2525 min-height : 100vh ;
2626 overflow : hidden;
27+ display : flex;
2728 }
2829
2930 .panel {
4142 font-size : 20px ;
4243 background-size : cover;
4344 background-position : center;
45+ flex : 1 ;
46+ justify-content : center;
47+ align-items : center;
48+ display : flex;
49+ flex-direction : column;
4450 }
4551
4652
5460 margin : 0 ;
5561 width : 100% ;
5662 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 );
5783 }
5884
5985 .panel p {
6894
6995 .panel .open {
7096 font-size : 40px ;
97+ flex : 5 ;
7198 }
7299
73100 </ style >
102129 </ div >
103130
104131 < 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+ }
105143
144+ panels . forEach ( panel => panel . addEventListener ( 'click' , toggleOpen ) ) ;
145+ panels . forEach ( panel => panel . addEventListener ( 'transitionend' , toggleActive ) ) ;
146+
106147 </ script >
107148
108149
You can’t perform that action at this time.
0 commit comments