Smooth Scroll to anchor on page - by kumapanda

3 replies2 participantsUpdated by Laranz

  • Avatar: kumapanda
    kumapanda
    Participant

    Hello,

    Can you tell me how can I link to a section with an anchor and have an smooth scroll effect. So that the page scrolls slowly down when I click on the link. I don’t want to use One page navigation. I only want to have a link

    
    <a href="#anchor">text</a>
    

    when user click on that link the site scrolls down to:

    
    <div id="anchor">....>/div>
    

    Is there some build in javascript in your theme I can use/ call without adding more javascript.

    THANK YOU!

    3 Answers

    Avatar: laranz
    Laranz
    Participant

    Hi there,
    I am delighted to assist you today. You can use this javascript code to get this feature.
    $(‘a[href*=#]’).click(function(event){
    $(‘html, body’).animate({
    scrollTop: $( $.attr(this, ‘href’) ).offset().top
    }, 500);
    event.preventDefault();
    });

    Hope I was able to help you with your concern.

    Avatar: kumapanda
    kumapanda
    Participant

    How can I limit this to a specific link? Can I add a link class somehow? Thank you :)!!!

    Avatar: laranz
    Laranz
    Participant

    Hi,

    Yes, you can change the selector of that script to your desired needs.

    $(‘a[href*=#]’) to $('.anchor')

    Let us know,

    Thanks,
    laranz.

You must be logged in to reply to this topic.Log in/Sign up