Created
December 20, 2018 22:46
-
-
Save frankthoeny/b35f9ca01df5993a2b62731d1b1e430a to your computer and use it in GitHub Desktop.
Toolbar with transition to transparency.
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
// Toolbar component | |
class toolbar extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
transform: null, | |
}; | |
} | |
componentDidMount() { | |
window.addEventListener('scroll', this.handleScroll); | |
} | |
componentWillUnmount() { | |
window.removeEventListener('scroll', this.handleScroll); | |
} | |
handleScroll = (event) => { | |
let scrollTop = window.pageYOffset || document.documentElement.scrollTop | |
this.setState({ | |
transform: scrollTop | |
}); | |
// Usage: | |
//<nav className={`toolbar__navigation ${(this.state.transform > 22)? ('transparent'):('')}`}> | |
// Fixed Top, Transition, opacity and height styles | |
//console.log(this.state.transform); | |
} | |
render() { | |
return( | |
<header className="toolbar fixed-top"> | |
<nav className={`toolbar__navigation navbar navbar-expand-md navbar-dark ${(this.state.transform > 22)? ('transparent'):('')}`}> | |
..... | |
</nav> | |
</header> | |
) | |
} | |
} |
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
nav.toolbar__navigation { | |
-webkit-transition: opacity 0.3s ease; | |
transition: opacity 0.3s ease; | |
} | |
nav.toolbar__navigation.transparent { | |
height: 60px; | |
opacity: 0.8; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment