Skip to content

Commit bd06878

Browse files
committed
fix: Parallax component for #808
1 parent ef02170 commit bd06878

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

packages/addons/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ This package contains the following:
44

55
- `@react-spring/addons` - Every addon in one tree-shakeable bundle
66
- `@react-spring/addons/parallax` - The `Parallax` and `ParallaxLayer`
7-
components
7+
components (only for `react-spring/web`)

packages/addons/src/parallax.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ export const ParallaxLayer = React.memo(
9191
setPosition(height, scrollTop, immediate = false) {
9292
const targetScroll = Math.floor(offset) * height
9393
const distance = height * offset + targetScroll * speed
94-
ctrl.update({
94+
ctrl.start({
9595
translate: -(scrollTop * speed) + distance,
9696
config: parent.config,
9797
immediate,
9898
})
9999
},
100100
setHeight(height, immediate = false) {
101-
ctrl.update({
101+
ctrl.start({
102102
space: height * factor,
103103
config: parent.config,
104104
immediate,
@@ -120,11 +120,13 @@ export const ParallaxLayer = React.memo(
120120
}
121121
})
122122

123-
const translate3d = ctrl.animated.translate.interpolate(
124-
horizontal
125-
? x => `translate3d(${x}px,0,0)`
126-
: y => `translate3d(0,${y}px,0)`
127-
)
123+
const translate3d = ctrl
124+
.get('translate')
125+
.to(
126+
horizontal
127+
? x => `translate3d(${x}px,0,0)`
128+
: y => `translate3d(0,${y}px,0)`
129+
)
128130

129131
return (
130132
<AnimatedView
@@ -135,7 +137,7 @@ export const ParallaxLayer = React.memo(
135137
backgroundRepeat: 'no-repeat',
136138
willChange: 'transform',
137139
[horizontal ? 'height' : 'width']: '100%',
138-
[horizontal ? 'width' : 'height']: ctrl.animated.space,
140+
[horizontal ? 'width' : 'height']: ctrl.get('space'),
139141
WebkitTransform: translate3d,
140142
MsTransform: translate3d,
141143
transform: translate3d,

0 commit comments

Comments
 (0)