Home > Enterprise >  Jquery scroll to id from another page
Jquery scroll to id from another page

Time:11-08

I have div with id="home-features" on home page. When I click on menu with it scrolls to div with id="home-features" But how do scroll from another page to home page and scroll to div id="home-features"

I need

  1. go to home page (mywebsite.com)
  2. scroll to div id="home-features"

I use this code for scrolling to div id="home-features" when I am on homepage

jQuery(".about-us-scrolling").click(function() {
    jQuery('html, body').animate({
        scrollTop: jQuery("#home-features").offset().top
    }, 2000);
});

How to change it for other pages?

CodePudding user response:

You can make scroll-behavior: smooth; to the home page and when you navigate to the home page just add a hash to id of the div you want to scroll to.

ex:

<a href="./home.html#home-features">Home</a>
  • Related