Skip to content

Instantly share code, notes, and snippets.

@hai5nguy
Last active February 6, 2017 21:52
Show Gist options
  • Save hai5nguy/bc843018139d3fe08a8899e94a715ce1 to your computer and use it in GitHub Desktop.
Save hai5nguy/bc843018139d3fe08a8899e94a715ce1 to your computer and use it in GitHub Desktop.
class Navigation extends React.Component {
constructor() {
super();
this.state = {
active: 'home',
};
}
changeNavigation = (e, section) => {
e.preventDefault();
var elem = document.getElementById(section);
document.body.scrollTop = elem.offsetTop;
this.setState({
active: section,
});
}
render() {
var { active } = this.state
return (
<div>
<nav>
<a href="#" className={'navigation' + active === ' home' ? ' active-nav' : ''} onClick={(e) => this.changeNavigation(e, active)}>HOME</a>
<a href="#" className={'navigation' + active === ' about' ? ' active-nav' : ''} onClick={(e) => this.changeNavigation(e, active)}>ABOUT</a>
<a href="#" className={'navigation' + active === ' faq' ? ' active-nav' : ''} onClick={(e) => this.changeNavigation(e, active)}>FAQ</a>
</nav>
</div>
);
}
}
class Content extends React.Component {
render() {
return (
<div>
<section id="home">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</section>
<section id="about">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</section>
<section id="faq">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</section>>
</div>
);
}
}
class PageContainer extends React.Component {
render() {
return (
<div>
<Navigation />
<Content />
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment