I am using react-router-hash-link instead of React-Scroll because I needed to link to another component as well as applying smooth scrolling. I am able to do an offest to the scroll but I do not know how add duration to the scroll. How do I add duration to the scroll? Many thanks in advance and greatly appreciate any help. Here is my code:
const scrollWidthOffset = (el) => {
const yCoordinate = el.getBoundingClientRect().top + window.pageYOffset;
const yOffset = -80;
window.scrollTo({ top: yCoordinate + yOffset, behavior: 'smooth' });
}
<div className="collapse navbar-collapse" id="navbarCollapse">
<div className="navbar-nav ml-auto">
<Link activeClass="active" smooth to="/#intro" scroll={el => scrollWidthOffset(el, -100)} className="nav-item nav-link">Home</Link>
<Link activeClass="active" smooth to="/#about" scroll={el => scrollWidthOffset(el, -80)} className="nav-item nav-link">About Us</Link>
<Link activeClass="active" smooth to="/#contact" scroll={el => scrollWidthOffset(el, -80)} className="nav-item nav-link">Contact</Link>
<Link activeClass="active" to="/login#loginform" className="nav-item nav-link">Login</Link>
</div>
</div>