Skip to content

Instantly share code, notes, and snippets.

@HansUXdev
Created July 2, 2019 07:05
Show Gist options
  • Save HansUXdev/1e6d67ad7a46d99b4e7bbf3457fef9ec to your computer and use it in GitHub Desktop.
Save HansUXdev/1e6d67ad7a46d99b4e7bbf3457fef9ec to your computer and use it in GitHub Desktop.
Some scrolly navbar
import React, { Component } from 'react';
import Scrollspy from 'react-scrollspy';
import FancyName from '../components/FancyName';
import {
Nav,
Navbar
} from 'react-bootstrap';
export default class NavigationBar extends Component {
render() {
const BGcolor = "#000";
const NavScrollColor = "#e40909";
const NavItemColor = "#fff";
const NavToggleColor = "#fff";
return (
<React.Fragment>
<Scrollspy items={ ['', 'about', 'service', 'blog'] }
scrolledPastClassName="navbar-reduce"
componentTag='div'
className=" "
// currentClassName="navbar-reduce"
>
<Navbar
fixed="top"
collapseOnSelect
expand="md"
className="navbar navbar-b navbar-trans "
>
<Navbar.Brand href="/">
<FancyName />
</Navbar.Brand>
<>
<Navbar.Toggle aria-controls="responsive-navbar-nav" children>
<span></span>
<span></span>
<span></span>
</Navbar.Toggle>
</>
<Navbar.Collapse id="responsive-navbar-nav" className="justify-content-end">
<Nav className="">
<Scrollspy items={ ['', "about"] } scrolledPastClassName="active" componentTag='li' className=" nav-item">
<Nav.Link href="#about">About</Nav.Link>
</Scrollspy>
<Scrollspy items={ ['', "service"] } scrolledPastClassName="active" componentTag='li' className=" nav-item">
<Nav.Link href="#service">Experiance</Nav.Link>
</Scrollspy>
<Scrollspy items={ ['', "blog"] } scrolledPastClassName="active" componentTag='li' className=" nav-item">
<Nav.Link className="nav-link js-scroll" href="#blog">Blog</Nav.Link>
</Scrollspy>
<Nav.Link className="nav-link js-scroll" href="/pdf">pdf</Nav.Link>
</Nav>
</Navbar.Collapse>
</Navbar>
</Scrollspy>
<style global jsx>{`
////
// Base Style for Nav
////
.navbar-b {
transition: all .5s ease-in-out;
background-color: transparent;
padding-top: 1.563rem;
padding-bottom: 1.563rem;
}
.navbar-b.navbar-reduce {
box-shadow: 0px 6px 9px 0px rgba(0, 0, 0, 0.06);
transition: all .5s ease-in-out;
background-color: ${BGcolor};
padding-top: 15px;
padding-bottom: 15px
}
.navbar-b.navbar-trans .nav-item,
.navbar-b.navbar-reduce .nav-item {
position: relative;
padding-right: 10px;
padding-left: 0;
}
.navbar-b.navbar-trans .nav-link,
.navbar-b.navbar-reduce .nav-link {
color: ${NavItemColor};
text-transform: uppercase;
font-weight: 600;
}
.navbar-b.navbar-trans .nav-link:before,
.navbar-b.navbar-reduce .nav-link:before {
content: '';
position: absolute;
margin-left: 0px;
width: 0%;
bottom: 0;
left: 0;
height: 2px;
transition: all 500ms ease;
}
.navbar-b.navbar-trans .nav-link:hover,
.navbar-b.navbar-reduce .nav-link:hover {
color: #1B1B1B;
}
.navbar-b.navbar-trans .nav-link:hover:before,
.navbar-b.navbar-reduce .nav-link:hover:before {
width: 35px;
}
.navbar-b.navbar-trans .show > .nav-link:before,
.navbar-b.navbar-trans .active > .nav-link:before,
.navbar-b.navbar-trans .nav-link.show:before,
.navbar-b.navbar-trans .nav-link.active:before,
.navbar-b.navbar-reduce .show > .nav-link:before,
.navbar-b.navbar-reduce .active > .nav-link:before,
.navbar-b.navbar-reduce .nav-link.show:before,
.navbar-b.navbar-reduce .nav-link.active:before {
width: 35px;
}
.navbar-b.navbar-trans .nav-link:before {
background-color: ${NavItemColor};
}
.navbar-b.navbar-trans .nav-link:hover {
color: ${NavItemColor};
}
.navbar-b.navbar-trans .show > .nav-link,
.navbar-b.navbar-trans .active > .nav-link,
.navbar-b.navbar-trans .nav-link.show,
.navbar-b.navbar-trans .nav-link.active {
color: ${NavItemColor};
}
.navbar-b.navbar-reduce {
transition: all .5s ease-in-out;
background-color: ${BGcolor};
padding-top: 15px;
padding-bottom: 15px;
}
.navbar-b.navbar-reduce .nav-link {
color: ${NavScrollColor};
}
.navbar-b.navbar-reduce .nav-link:before {
background-color: ${NavScrollColor};
}
.navbar-b.navbar-reduce .nav-link:hover {
color: ${NavScrollColor};
}
.navbar-b.navbar-reduce .show > .nav-link,
.navbar-b.navbar-reduce .active > .nav-link,
.navbar-b.navbar-reduce .nav-link.show,
.navbar-b.navbar-reduce .nav-link.active {
color: ${NavScrollColor};
}
.navbar-b.navbar-reduce .navbar-brand {
color: ${NavScrollColor};
}
.navbar-b .navbar-brand {
color: #fff;
font-size: 1.6rem;
font-weight: 600;
}
.navbar-b .navbar-nav .dropdown-item.show .dropdown-menu,
.navbar-b .dropdown.show .dropdown-menu,
.navbar-b .dropdown-btn.show .dropdown-menu {
-webkit-transform: translate3d(0px, 0px, 0px);
transform: translate3d(0px, 0px, 0px);
visibility: visible !important;
}
.navbar-b .dropdown-menu {
margin: 1.12rem 0 0;
border-radius: 0;
}
.navbar-b .dropdown-menu .dropdown-item {
padding: .7rem 1.7rem;
transition: all 500ms ease;
}
.navbar-b .dropdown-menu .dropdown-item:hover {
background-color: #0078ff;
color: #fff;
transition: all 500ms ease;
}
.navbar-b .dropdown-menu .dropdown-item.active {
background-color: #0078ff;
}
/*--/ Hamburger Navbar /--*/
.navbar-toggler span,
.navbar-b.navbar-reduce .navbar-toggler span
{
background-color: ${NavToggleColor};
}
.navbar-toggler {
position: relative;
}
.navbar-toggler:focus,
.navbar-toggler:active {
outline: 0;
}
.navbar-toggler span {
display: block;
height: 3px;
width: 25px;
margin-top: 4px;
margin-bottom: 4px;
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
left: 0;
opacity: 1;
transition: all .35s ease-in-out;
}
.navbar-toggler span:nth-child(1),
.navbar-toggler span:nth-child(3) {
// transition: -webkit-transform .35s ease-in-out;
transition: transform .35s ease-in-out, -webkit-transform .35s ease-in-out;
transition: all .35s ease-in-out;
}
////////
// When clicked
////////
.navbar-toggler.collapsed span:nth-child(1) {
position: absolute;
left: 12px;
top: 10px;
-webkit-transform: rotate(135deg);
transform: rotate(135deg);
opacity: 0.9;
}
// Remove the middle
.navbar-toggler.collapsed span:nth-child(2) {
height: 12px;
visibility: hidden;
background-color: transparent;
}
.navbar-toggler.collapsed span:nth-child(3) {
position: absolute;
left: 12px;
top: 10px;
-webkit-transform: rotate(-135deg);
transform: rotate(-135deg);
opacity: 0.9;
}
`}</style>
</React.Fragment>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment