0

Has anyone had this problem before? I am on an internal page (like about.html) and I want to scrollTop to an anchor in home page (like home.html#sectionID), but I don't know how can I do that with jQuery.. I've already tried some stuffs but it doesn't work. Here is my actual code that works if I am in the home page..

  $(".anchor-link").click(function(e) {
    e.preventDefault();
    $('html, body').animate({
        scrollTop: $( $(this).attr('href') ).offset().top + (-117)
    }, 1000);
    return false;
  });

1 Answers1

0

Instead of using $(this).attr('href'), use any selector in the top of page where you want to scroll. If you have #home id in top then you need to use:

$('html, body').animate({
    scrollTop: $('#home').offset().top + (-117)
}, 1000);
Prajwal Bati
  • 185
  • 8
  • 19