File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2626 .panels {
2727 min-height : 100vh ;
2828 overflow : hidden;
29+ display : flex;
2930 }
3031
3132 .panel {
4344 font-size : 20px ;
4445 background-size : cover;
4546 background-position : center;
47+
48+ flex : 1 ;
49+ display : flex;
50+ flex-direction : column;
51+ justify-content : center;
52+ align-items : center;
4653 }
4754
4855 .panel1 { background-image : url (https://source.unsplash.com/gYl-UtwNg_I/1500x1500); }
5663 margin : 0 ;
5764 width : 100% ;
5865 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 );
5986 }
6087
6188 .panel p {
7198
7299 .panel .open {
73100 font-size : 40px ;
101+ flex : 5 ;
74102 }
75103
76104 </ style >
105133 </ div >
106134
107135 < 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+ }
108147
148+ panels . forEach ( panel => panel . addEventListener ( 'click' , ( event ) => toggleOpen ( event , panel ) ) ) ;
149+ panels . forEach ( panel => panel . addEventListener ( 'transitionend' , ( event ) => toggleActive ( event , panel ) ) ) ;
109150 </ script >
110151
111152
You can’t perform that action at this time.
0 commit comments