Last active
February 9, 2017 20:11
-
-
Save dcolucci/be4f1ce874806196fd88c30dfcea2d8b to your computer and use it in GitHub Desktop.
This file contains 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
// A pseudocode proposal setup for facilitating animation effects on scroll depth for longform article | |
// sample effect: https://readymag.com/u59457328/681360/ | |
// | |
// Utilizes the ScrollMonitor from Self: | |
// https://github.com/CondeNast/autopilot-self/blob/master/src/app/views/components/ScrollMonitor.js | |
class LongformPage extends React.Component { | |
render() { | |
return ( | |
<BasePage> | |
<LongformArticle article={this.props.article} /> | |
</BasePage> | |
); | |
} | |
} | |
class LongformArticle extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
isScrolledPastHero: false | |
}; | |
this._handleScrollPastHero = this._handleScrollPastHero.bind(this); | |
this._handleScrollToHero = this._handleScrollToHero.bind(this); | |
} | |
_handleScrollPastHero(event) { | |
event.preventDefault(); // IDK if this is needed | |
this.setState({ | |
isScrolledPastHero: true | |
}); | |
} | |
_handleScrollToHero(event) { | |
event.preventDefault(); // IDK if this is needed | |
this.setState({ | |
isScrolledPastHero: false | |
}); | |
} | |
render () { | |
// LongformArticleBody component accepts a boolean prop for `isScrolledTo` (or whatever) | |
// It internally adds a corresponding classname to its top-level component | |
// We wrap the Hero in ScrollMonitor to trigger state change when it has exited viewport | |
// We transition background & text color on the classname | |
return [ | |
<ScrollMonitor onExitViewport={this._handleScrollPastHero} onEnterViewport={this._handleScrollToHero}> | |
<Hero {...this.props.article.hero} /> | |
</ScrollMonitor> | |
<LongformArticleBody isScrolledTo={this.state.isScrolledPastHero} /> | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment