Skip to content

Commit

Permalink
feat(parallax): child horizontal prop defaults to parent's (#1458)
Browse files Browse the repository at this point in the history
* fix(parallax): child horizontal default to parents

* fix: remove translate rule of number layers

* refactor: replace reassignment with new const

Co-authored-by: Josh <[email protected]>
  • Loading branch information
kindoflew and joshuaellis authored Apr 25, 2021
1 parent 0206409 commit 9568020
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 0 additions & 1 deletion demo/src/sandboxes/parallax/src/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
.number span {
display: inline-block;
position: relative;
transform: translate3d(-35%, 0, 0);
}

.slopeBegin {
Expand Down
12 changes: 9 additions & 3 deletions packages/parallax/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface IParallaxLayer {

export interface IParallax {
config: ConfigProp
horizontal: boolean
busy: boolean
space: number
offset: number
Expand Down Expand Up @@ -101,8 +102,12 @@ export const ParallaxLayer = React.memo(
}
})

// Layer's horizontal defaults to parent's horizontal if not set.
const scrollHorizontal =
horizontal === undefined ? parent.horizontal : horizontal

const translate3d = ctrl.springs.translate.to(
horizontal
scrollHorizontal
? x => `translate3d(${x}px,0,0)`
: y => `translate3d(0,${y}px,0)`
)
Expand All @@ -115,8 +120,8 @@ export const ParallaxLayer = React.memo(
backgroundSize: 'auto',
backgroundRepeat: 'no-repeat',
willChange: 'transform',
[horizontal ? 'height' : 'width']: '100%',
[horizontal ? 'width' : 'height']: ctrl.springs.space,
[scrollHorizontal ? 'height' : 'width']: '100%',
[scrollHorizontal ? 'width' : 'height']: ctrl.springs.space,
WebkitTransform: translate3d,
msTransform: translate3d,
transform: translate3d,
Expand Down Expand Up @@ -155,6 +160,7 @@ export const Parallax = React.memo(
const state: IParallax = useMemoOne(
() => ({
config,
horizontal,
busy: false,
space: 0,
current: 0,
Expand Down

0 comments on commit 9568020

Please sign in to comment.