Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cc95a1b

Browse files
HiteshGoranahitesh-gorana
andauthored
chore: refactor getExpandedStyle.ts (jscottsmith#209)
Co-authored-by: Hitesh <hitesh.g@smarter.codes>
1 parent 2ff50ca commit cc95a1b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

‎src/components/ParallaxBanner/helpers/getExpandedStyle.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /