@@ -98,37 +98,41 @@ export interface SlideParams {
98
98
delay ?: number ;
99
99
duration ?: number ;
100
100
easing ?: EasingFunction ;
101
+ axis ?: 'x' | 'y' ;
101
102
}
102
103
103
104
export function slide ( node : Element , {
104
105
delay = 0 ,
105
106
duration = 400 ,
106
- easing = cubicOut
107
+ easing = cubicOut ,
108
+ axis = 'y'
107
109
} : SlideParams = { } ) : TransitionConfig {
108
110
const style = getComputedStyle ( node ) ;
109
111
const opacity = + style . opacity ;
110
- const height = parseFloat ( style . height ) ;
111
- const padding_top = parseFloat ( style . paddingTop ) ;
112
- const padding_bottom = parseFloat ( style . paddingBottom ) ;
113
- const margin_top = parseFloat ( style . marginTop ) ;
114
- const margin_bottom = parseFloat ( style . marginBottom ) ;
115
- const border_top_width = parseFloat ( style . borderTopWidth ) ;
116
- const border_bottom_width = parseFloat ( style . borderBottomWidth ) ;
117
-
112
+ const primary_property = axis === 'y' ? 'height' : 'width' ;
113
+ const primary_property_value = parseFloat ( style [ primary_property ] ) ;
114
+ const secondary_properties = axis === 'y' ? [ 'top' , 'bottom' ] : [ 'left' , 'right' ] ;
115
+ const capitalized_secondary_properties = secondary_properties . map ( ( e ) => `${ e [ 0 ] . toUpperCase ( ) } ${ e . slice ( 1 ) } ` ) ;
116
+ const padding_start_value = parseFloat ( style [ `padding${ capitalized_secondary_properties [ 0 ] } ` ] ) ;
117
+ const padding_end_value = parseFloat ( style [ `padding${ capitalized_secondary_properties [ 1 ] } ` ] ) ;
118
+ const margin_start_value = parseFloat ( style [ `margin${ capitalized_secondary_properties [ 0 ] } ` ] ) ;
119
+ const margin_end_value = parseFloat ( style [ `margin${ capitalized_secondary_properties [ 1 ] } ` ] ) ;
120
+ const border_width_start_value = parseFloat ( style [ `border${ capitalized_secondary_properties [ 0 ] } Width` ] ) ;
121
+ const border_width_end_value = parseFloat ( style [ `border${ capitalized_secondary_properties [ 1 ] } Width` ] ) ;
118
122
return {
119
123
delay,
120
124
duration,
121
125
easing,
122
126
css : t =>
123
127
'overflow: hidden;' +
124
128
`opacity: ${ Math . min ( t * 20 , 1 ) * opacity } ;` +
125
- `height : ${ t * height } px;` +
126
- `padding-top : ${ t * padding_top } px;` +
127
- `padding-bottom : ${ t * padding_bottom } px;` +
128
- `margin-top : ${ t * margin_top } px;` +
129
- `margin-bottom : ${ t * margin_bottom } px;` +
130
- `border-top -width: ${ t * border_top_width } px;` +
131
- `border-bottom -width: ${ t * border_bottom_width } px;`
129
+ `${ primary_property } : ${ t * primary_property_value } px;` +
130
+ `padding-${ secondary_properties [ 0 ] } : ${ t * padding_start_value } px;` +
131
+ `padding-${ secondary_properties [ 1 ] } : ${ t * padding_end_value } px;` +
132
+ `margin-${ secondary_properties [ 0 ] } : ${ t * margin_start_value } px;` +
133
+ `margin-${ secondary_properties [ 1 ] } : ${ t * margin_end_value } px;` +
134
+ `border-${ secondary_properties [ 0 ] } -width: ${ t * border_width_start_value } px;` +
135
+ `border-${ secondary_properties [ 1 ] } -width: ${ t * border_width_end_value } px;`
132
136
} ;
133
137
}
134
138
0 commit comments