[Resolved] smooth-scroll links from other pages

Home Forums Support [Resolved] smooth-scroll links from other pages

Home Forums Support smooth-scroll links from other pages

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1041196
    JBD

    If I’m linking to parts of a page using anchor links, is it possible to smooth scroll to the section in question if coming from another page?

    The reason I ask is that I have a menu that appears on multiple page with links to parts of the page, but the links are absolute, eg href=”/sub-page#section2″

    I looked at adding the code previously mentioned:-

    add_filter( 'generate_smooth_scroll_elements', function( $elements ) {
      $elements[] = 'a[href*="#"]:not(.generate-back-to-top)';
      
      return $elements;
    } );

    but I don’t think this would work on links such as

    <a href="/sub-page#section2" >menu link</a>

    #1041204
    JBD

    Update, If I change the links from
    <a href="/sub-page#section2" >menu link</a>
    to
    <a href="/sub-page/#section2" >menu link</a>
    Then the smooth-scroll works if I’m on the same page.

    However it doesnt smooth-scroll if I’m linking from another page.

    Is this possible?

    #1041217
    David
    Staff
    Customer Support

    Hi there,

    smooth-scroll will only work on anchors that are on the same page. Not possible to make it apply when navigating to a new page.

    #1041497
    JBD

    ok, good to know, thanks

    #1041829
    Tom
    Lead Developer
    Lead Developer

    It may be possible if you use a jQuery smooth scroll script instead of our vanilla javascript smooth scroll script. This might help: https://stackoverflow.com/a/46673487

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.