File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
src/components/ParallaxBanner/helpers Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,12 @@ const FALLBACK_RECT = {
55 height : 0 ,
66} ;
77
8- export function getExpandedStyle ( layer : BannerLayer ) {
8+ type ExpandedStyle = {
9+ top ?: string ;
10+ bottom ?: string ;
11+ } ;
12+
13+ export function getExpandedStyle ( layer : BannerLayer ) : ExpandedStyle {
914 if ( Array . isArray ( layer . translateY ) ) {
1015 const translateYStart = parseValueAndUnit ( layer . translateY [ 0 ] ) ;
1116 const translateYEnd = parseValueAndUnit ( layer . translateY [ 1 ] ) ;
@@ -19,7 +24,7 @@ export function getExpandedStyle(layer: BannerLayer) {
1924
2025 if ( translateYStart . unit === '%' && translateYEnd . unit === '%' ) {
2126 const clientRect =
22- layer . targetElement ?. getBoundingClientRect ( ) || FALLBACK_RECT ;
27+ layer . targetElement ?. getBoundingClientRect ( ) ?? FALLBACK_RECT ;
2328 const top = Math . abs ( clientRect . height * 0.01 * translateYEnd . value ) * - 1 ;
2429 const bottom =
2530 Math . abs ( clientRect . height * 0.01 * translateYStart . value ) * - 1 ;
@@ -29,13 +34,16 @@ export function getExpandedStyle(layer: BannerLayer) {
2934 } ;
3035 }
3136 }
37+
3238 if ( layer . speed ) {
3339 const speed = layer . speed || 0 ;
40+ const absSpeed = Math . abs ( speed ) * 10 * - 1 ;
3441
3542 return {
36- top : Math . abs ( speed ) * 10 * - 1 + 'px' ,
37- bottom : Math . abs ( speed ) * 10 * - 1 + 'px' ,
43+ top : ` ${ absSpeed } px` ,
44+ bottom : ` ${ absSpeed } px` ,
3845 } ;
3946 }
47+
4048 return { } ;
4149}
You can’t perform that action at this time.
0 commit comments