11<!DOCTYPE html>
22< html lang ="en ">
3+
34< head >
45 < meta charset ="UTF-8 ">
56 < title > Flex Panels 💪</ title >
67 < link href ='https://fonts.googleapis.com/css?family=Amatic+SC ' rel ='stylesheet ' type ='text/css '>
78</ head >
9+
810< body >
911 < style >
1012 html {
1416 font-size : 20px ;
1517 font-weight : 200 ;
1618 }
17-
19+
1820 body {
1921 margin : 0 ;
2022 }
21-
22- * , * : before , * : after {
23+
24+ * ,
25+ * : before ,
26+ * : after {
2327 box-sizing : inherit;
2428 }
2529
2630 . panels {
2731 min-height : 100vh ;
2832 overflow : hidden;
33+ display : flex;
2934 }
3035
3136 . panel {
3237 background : # 6B0F9C;
33- box-shadow : inset 0 0 0 5px rgba ( 255 , 255 , 255 , 0.1 ) ;
38+ box-shadow : inset 0 0 0 5px rgba ( 255 , 255 , 255 , 0.1 ) ;
3439 color : white;
3540 text-align : center;
3641 align-items : center;
3742 /* Safari transitionend event.propertyName === flex */
3843 /* Chrome + FF transitionend event.propertyName === flex-grow */
3944 transition :
40- font-size 0.7s cubic-bezier ( 0.61 , -0.19 , 0.7 , -0.11 ) ,
41- flex 0.7s cubic-bezier ( 0.61 , -0.19 , 0.7 , -0.11 ) ,
45+ font-size 0.7s cubic-bezier ( 0.61 , -0.19 , 0.7 , -0.11 ) ,
46+ flex 0.7s cubic-bezier ( 0.61 , -0.19 , 0.7 , -0.11 ) ,
4247 background 0.2s ;
4348 font-size : 20px ;
4449 background-size : cover;
4550 background-position : center;
51+ display : flex;
52+ flex-direction : column;
53+ justify-content : center;
54+ align-items : center;
55+ flex : 1 ;
56+ }
57+
58+ . panel1 {
59+ background-image : url ( https://source.unsplash.com/gYl-UtwNg_I/1500x1500) ;
4660 }
4761
48- . panel1 { background-image : url ( https://source.unsplash.com/gYl-UtwNg_I/1500x1500) ; }
49- . panel2 { background-image : url ( https://source.unsplash.com/rFKUFzjPYiQ/1500x1500) ; }
50- . panel3 { background-image : url ( https://images.unsplash.com/photo-1465188162913-8fb5709d6d57?ixlib=rb-0.3.5&q=80&fm=jpg&crop=faces&cs=tinysrgb&w=1500&h=1500&fit=crop&s=967e8a713a4e395260793fc8c802901d) ; }
51- . panel4 { background-image : url ( https://source.unsplash.com/ITjiVXcwVng/1500x1500) ; }
52- . panel5 { background-image : url ( https://source.unsplash.com/3MNzGlQM7qs/1500x1500) ; }
62+ . panel2 {
63+ background-image : url ( https://source.unsplash.com/rFKUFzjPYiQ/1500x1500) ;
64+ }
65+
66+ . panel3 {
67+ background-image : url ( https://images.unsplash.com/photo-1465188162913-8fb5709d6d57?ixlib=rb-0.3.5&q=80&fm=jpg&crop=faces&cs=tinysrgb&w=1500&h=1500&fit=crop&s=967e8a713a4e395260793fc8c802901d) ;
68+ }
69+
70+ . panel4 {
71+ background-image : url ( https://source.unsplash.com/ITjiVXcwVng/1500x1500) ;
72+ }
73+
74+ . panel5 {
75+ background-image : url ( https://source.unsplash.com/3MNzGlQM7qs/1500x1500) ;
76+ }
5377
5478 /* Flex Children */
55- . panel > * {
79+ . panel > * {
5680 margin : 0 ;
5781 width : 100% ;
5882 transition : transform 0.5s ;
83+ flex : 1 0 auto;
84+ display : flex;
85+ justify-content : center;
86+ align-items : center;
87+ }
88+
89+ . panel > * : first-child {
90+ transform : translateY ( -100% ) ;
91+ }
92+
93+ . panel . open-active > * : first-child {
94+ transform : translateY ( 0 ) ;
95+ }
96+
97+ . panel > * : last-child {
98+ transform : translateY ( 100% ) ;
99+ }
100+
101+ . panel . open-active > * : last-child {
102+ transform : translateY ( 0 ) ;
59103 }
60104
61105 . panel p {
64108 text-shadow : 0 0 4px rgba ( 0 , 0 , 0 , 0.72 ) , 0 0 14px rgba ( 0 , 0 , 0 , 0.45 ) ;
65109 font-size : 2em ;
66110 }
67-
111+
68112 . panel p : nth-child ( 2 ) {
69113 font-size : 4em ;
70114 }
71115
72116 . panel . open {
117+ flex : 5 ;
73118 font-size : 40px ;
74119 }
75-
76120 </ style >
77121
78122
105149 </ div >
106150
107151 < script >
108-
152+ const panels = document . querySelectorAll ( '.panel' ) ;
153+ function toggleOpen ( ) {
154+ this . classList . toggle ( 'open' ) ;
155+ }
156+ function toggleActive ( e ) {
157+ // console.log(e.propertyName);
158+ if ( e . propertyName . includes ( 'flex' ) )
159+ this . classList . toggle ( 'open-active' ) ;
160+ }
161+ panels . forEach ( panel => panel . addEventListener ( 'click' , toggleOpen ) ) ;
162+ panels . forEach ( panel => panel . addEventListener ( 'transitionend' , toggleActive ) ) ;
109163 </ script >
110164
111165
112166
113167</ body >
114- </ html >
168+
169+ </ html >
0 commit comments