Topic: Navigate to anchor on another page

depicturevis pro asked 6 years ago


Hi, The title explains it. I cannot seem to navigate to another page anchor, it simply redirects to the top of the page. Is there a way to use smooth scroll for this? Regards, Kristian

Rafał Rogulski free answered 6 years ago


Hi, Yes, you can use the smooth scroll for this but it is little tricky. First, you must add #id to URL which redirects us to the second page <a href="index.html#header">Go to next page</a> in this page, you must add this script:
$(document).ready(function() {
    var target = $(location).attr("hash");
    var offset = ($(this).attr('data-offset') ? $(this).attr('data-offset') : 0);
    $('body,html').animate({
        scrollTop: $(target).offset().top - offset
    }, 700);
});
this script takes this #id, searching on this page for an element with this 'id', and start an animation. Regards Regards

LuisMiguel_0795 free commented 3 years ago

worked for me thanks!



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: General Bootstrap questions
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No
Tags