Created
September 15, 2017 00:25
-
-
Save JulianJorgensen/0d5fa50cef01bf362dba240892ef0ed9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
componentDidMount() { | |
// add this Parallax element to the global listener | |
if (typeof ParallaxController === 'undefined') { | |
throw new Error( | |
'Must initialize the ParallaxController before adding React Parallax components.' | |
); | |
} | |
// create a new parallax element and save the reference | |
this.element = ParallaxController.createElement({ | |
elInner: this._inner, | |
elOuter: this._outer, | |
props: { | |
disabled: this.props.disabled, | |
offsetXMax: this.props.offsetXMax, | |
offsetXMin: this.props.offsetXMin, | |
offsetYMax: this.props.offsetYMax, | |
offsetYMin: this.props.offsetYMin, | |
fadeSpeed: this.props.fadeSpeed, | |
slowerScrollRate: this.props.slowerScrollRate, | |
}, | |
}); | |
} | |
componentWillReceiveProps(nextProps) { | |
// updates the elements props when changed | |
if (this.props !== nextProps) { | |
ParallaxController.updateElement(this.element, { | |
props: { | |
disabled: nextProps.disabled, | |
offsetXMax: nextProps.offsetXMax, | |
offsetXMin: nextProps.offsetXMin, | |
offsetYMax: nextProps.offsetYMax, | |
offsetYMin: nextProps.offsetYMin, | |
fadeSpeed: nextProps.fadeSpeed, | |
slowerScrollRate: nextProps.slowerScrollRate, | |
}, | |
}); | |
} | |
// resets element styles when disabled | |
if (this.props.disabled !== nextProps.disabled && nextProps.disabled) { | |
ParallaxController.resetElementStyles(this.element); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment