JSFiddle - React, Tailwind, and code Playground
HTML
<a href="#test" class="smoothScroll">Go to test</a>
<div id="test"></div>
CSS
#test {
background-color: yellowgreen;
width: 300px;
height: 300px;
margin: 2000px auto;
}
JavaScript
// SmoothSCroll
var smoothScroll = document.querySelectorAll('.smoothScroll');
[].forEach.call(smoothScroll, function (el) {
el.addEventListener('click', function() {
var offset = $(this.hash).offset().top;;
$('html, body').stop().animate({
scrollTop: offset - (window.innerHeight/2) + ($(this.hash).innerHeight()/2)
}, 400 );
return false;
});
});