Scroll to Element

HTML
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div data-jumper="#one">Go To Section One</div> <div data-jumper="#two">Go to Setion Two</div> <hr> <div id="one">First Element</div> <hr> <div id="two">Second Element</div> <hr>
CSS
hr { height: 100vh; }
JAVASCRIPT
$( document ).ready(function() { $("[data-jumper^='#']").click(function(e) { var position = $($(this).attr("data-jumper")).offset().top; $("body, html").animate({scrollTop: position}, 2000); }); });
Expand for more options Login