Skip to content

Commit 3b9ab3e

Browse files
committed
smooth scroll added
1 parent 79035c3 commit 3b9ab3e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/components/Navbar/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState, useEffect } from 'react';
22
import { FaBars } from 'react-icons/fa';
33
import { IconContext } from 'react-icons/lib';
4+
import { animateScroll as scroll } from 'react-scroll';
45
import { MenuIcon, Nav, NavbarContainer, NavItem, NavLink, NavLogo, NavMenu, NavBtn, NavBtnLink } from './NavbarElements';
56

67
const Navbar = ({ toggle }) => {
@@ -18,29 +19,33 @@ const Navbar = ({ toggle }) => {
1819
window.addEventListener('scroll', changeNav);
1920
}, []);
2021

22+
const toggleHome = () => {
23+
scroll.scrollToTop();
24+
};
25+
2126
return (
2227
<>
2328
<IconContext.Provider value={{ color: '#fff' }}>
2429
<Nav scrollNav={scrollNav}>
2530
<NavbarContainer>
26-
<NavLogo to='/'>
31+
<NavLogo to='/' onClick={toggleHome}>
2732
logo
2833
</NavLogo>
2934
<MenuIcon onClick={toggle}>
3035
<FaBars />
3136
</MenuIcon>
3237
<NavMenu>
3338
<NavItem>
34-
<NavLink to='about'>About</NavLink>
39+
<NavLink to='about' smooth={true} duration={500} spy={true} exact='true' offset={-80} >About</NavLink>
3540
</NavItem>
3641
<NavItem>
37-
<NavLink to='discover'>Discover</NavLink>
42+
<NavLink to='discover' smooth={true} duration={500} spy={true} exact='true' offset={-80}>Discover</NavLink>
3843
</NavItem>
3944
<NavItem>
40-
<NavLink to='services'>Services</NavLink>
45+
<NavLink to='services' smooth={true} duration={500} spy={true} exact='true' offset={-80}>Services</NavLink>
4146
</NavItem>
4247
<NavItem>
43-
<NavLink to='signup'>Sign Up</NavLink>
48+
<NavLink to='signup' smooth={true} duration={500} spy={true} exact='true' offset={-80}>Sign Up</NavLink>
4449
</NavItem>
4550
</NavMenu>
4651
<NavBtn>

0 commit comments

Comments
 (0)