Categories
Uncategorised

Smooth Scroll to Anchor

Add the class “scrollto” to the you <a> tag and add the following to your javascript.

// Smooth Scroll
$(document).on('click', 'a', function(event){
    if ( $( this ).hasClass( "scrollto" ) ) {
        event.preventDefault();
        $('html, body').animate({
            scrollTop: $($.attr(this, 'href')).offset().top
        }, 500);
    }
});

Example link

<a href="#content" class="scrollto">My Link</a>

 

Leave a Reply