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 = {
5
5
height : 0 ,
6
6
} ;
7
7
8
- export function getExpandedStyle ( layer : BannerLayer ) {
8
+ type ExpandedStyle = {
9
+ top ?: string ;
10
+ bottom ?: string ;
11
+ } ;
12
+
13
+ export function getExpandedStyle ( layer : BannerLayer ) : ExpandedStyle {
9
14
if ( Array . isArray ( layer . translateY ) ) {
10
15
const translateYStart = parseValueAndUnit ( layer . translateY [ 0 ] ) ;
11
16
const translateYEnd = parseValueAndUnit ( layer . translateY [ 1 ] ) ;
@@ -19,7 +24,7 @@ export function getExpandedStyle(layer: BannerLayer) {
19
24
20
25
if ( translateYStart . unit === '%' && translateYEnd . unit === '%' ) {
21
26
const clientRect =
22
- layer . targetElement ?. getBoundingClientRect ( ) || FALLBACK_RECT ;
27
+ layer . targetElement ?. getBoundingClientRect ( ) ?? FALLBACK_RECT ;
23
28
const top = Math . abs ( clientRect . height * 0.01 * translateYEnd . value ) * - 1 ;
24
29
const bottom =
25
30
Math . abs ( clientRect . height * 0.01 * translateYStart . value ) * - 1 ;
@@ -29,13 +34,16 @@ export function getExpandedStyle(layer: BannerLayer) {
29
34
} ;
30
35
}
31
36
}
37
+
32
38
if ( layer . speed ) {
33
39
const speed = layer . speed || 0 ;
40
+ const absSpeed = Math . abs ( speed ) * 10 * - 1 ;
34
41
35
42
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` ,
38
45
} ;
39
46
}
47
+
40
48
return { } ;
41
49
}
You can’t perform that action at this time.
0 commit comments