0 points

jQuery Smooth Scroll


dashboard

Wed Jun 03 2020 16:41:47 GMT+0000 (UTC)

Posted by @braydenw45 #html

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("a").on('click', function(event) {
    if (this.hash !== "") {
      event.preventDefault();
      var hash = this.hash;
      $('html, body').animate({
        scrollTop: $(hash).offset().top
      }, 800, function(){
        window.location.hash = hash;
      });
    }
  });
});
</script>
content_copy Copy

Paste this into your HTML to get a JS script with jQuery that adds smooth scrolling to <a> tags.

https://www.w3schools.com/howto/howto_css_smooth_scroll.asp