feat(ui-toolkit): improve parallax scroll behaviour
This commit is contained in:
parent
155a065281
commit
a1154b2520
@ -82,18 +82,19 @@ export default class extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scrollStopHandler = () => {
|
scrollStopHandler = () => {
|
||||||
window.clearTimeout(isScrolling);
|
window.removeEventListener('scroll', this.scrollStopHandler);
|
||||||
isScrolling = setTimeout(() => {
|
window.addEventListener('scroll', this.checkpoint);
|
||||||
|
|
||||||
isScrolledOutsideView()
|
isScrolledOutsideView()
|
||||||
? this.setState({ show: false }, () =>
|
? this.setState({ show: false })
|
||||||
window.removeEventListener('scroll', this.scrollStopHandler)
|
|
||||||
)
|
|
||||||
: this.skipParallax();
|
: this.skipParallax();
|
||||||
}, 66);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
skipParallax = () => {
|
skipParallax = () => {
|
||||||
if (this.state.show) {
|
if (
|
||||||
|
this.state.show &&
|
||||||
|
window.scrollY < document.getElementsByTagName('header')[0].offsetTop
|
||||||
|
) {
|
||||||
window.scroll({
|
window.scroll({
|
||||||
top: document.getElementsByTagName('header')[0].offsetTop,
|
top: document.getElementsByTagName('header')[0].offsetTop,
|
||||||
left: 0,
|
left: 0,
|
||||||
@ -102,6 +103,13 @@ export default class extends Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
checkpoint = () => {
|
||||||
|
if (isScrolledOutsideView()) {
|
||||||
|
window.removeEventListener('scroll', this.checkpoint);
|
||||||
|
this.setState({ show: false });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
window.addEventListener('resize', () => {
|
window.addEventListener('resize', () => {
|
||||||
this.setState({
|
this.setState({
|
||||||
@ -124,7 +132,7 @@ export default class extends Component {
|
|||||||
{array.map((g, i) => (
|
{array.map((g, i) => (
|
||||||
<Gutter key={g} style={{ left: gutterWidth * i }} />
|
<Gutter key={g} style={{ left: gutterWidth * i }} />
|
||||||
))}
|
))}
|
||||||
<Parallax offsetYMax={50} offsetYMin={-50} slowerScrollRate tag="main">
|
<Parallax offsetYMax={50} offsetYMin={-50} tag="main">
|
||||||
<Text>
|
<Text>
|
||||||
<Img src={Plus} />
|
<Img src={Plus} />
|
||||||
<Img topRight src={Plus} />
|
<Img topRight src={Plus} />
|
||||||
@ -136,6 +144,10 @@ export default class extends Component {
|
|||||||
elements, components and guidelines, for anyone developing
|
elements, components and guidelines, for anyone developing
|
||||||
products within the Joyent and Triton ecosystems.
|
products within the Joyent and Triton ecosystems.
|
||||||
</P>
|
</P>
|
||||||
|
</Text>
|
||||||
|
</Parallax>
|
||||||
|
<Parallax offsetYMax={200} offsetYMin={0} slowerScrollRate tag="main">
|
||||||
|
<Text>
|
||||||
<P white style={{ marginTop: remcalc(60), position: 'absolute' }}>
|
<P white style={{ marginTop: remcalc(60), position: 'absolute' }}>
|
||||||
Scroll down
|
Scroll down
|
||||||
</P>
|
</P>
|
||||||
|
@ -61,7 +61,7 @@ const StyleGuideRenderer = ({
|
|||||||
<ThemeProvider theme={fullTheme}>
|
<ThemeProvider theme={fullTheme}>
|
||||||
<ParallaxProvider>
|
<ParallaxProvider>
|
||||||
<Fragment>
|
<Fragment>
|
||||||
{link === '/' ? <Parallax hideAfterScroll="true" /> : null}
|
{link === '/' ? <Parallax hideAfterScroll={true} /> : null}
|
||||||
<Header />
|
<Header />
|
||||||
<Grid style={{ marginLeft: 0, zIndex: 2, position: 'relative' }}>
|
<Grid style={{ marginLeft: 0, zIndex: 2, position: 'relative' }}>
|
||||||
<Main>
|
<Main>
|
||||||
|
Loading…
Reference in New Issue
Block a user