How to link to a section on another page and smooth scroll to the section?

I’m trying to link a button from one page to a section on my homepage

I found this script but feel I’m not using it properly

Could someone guide me on this?


$(document).ready(function() {
  // Add smooth scrolling to all links
  $("a").on('click', function(event) {

    // Make sure this.hash has a value before overriding default behavior
    if (this.hash !== "") {

      // Store hash
      var hash = this.hash;

      // Using jQuery's animate() method to add smooth page scroll
      // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
      $('html, body').animate({
        scrollTop: $(hash).offset().top
      }, 2000, function() {

        // Add hash (#) to URL when done scrolling (default click behavior)
        window.location.hash = hash;
      return false;
    } // End if

Here is my site Read-Only: LINK
(how to share your site Read-Only link)

It’s about how to use this.hash. Can’t wrap my head around it. Any help anyone?

Hi! I’m having the same problem. Have you had any luck figuring it out?


I think i got it working. You can see the read-only for the code and the live site to see it in action :wink:

Read-only Link

Live Site

Clone it here

1 Like

Thank you so much!! This is very helpful :).

1 Like