Scroll to Element jQuery

A useful function to scroll to element without a javascript or jquery plugin.

This is a small function to scroll to a desired element. This was written Cory LaViska and in my opinion a very good function to use for your future projects. This is short and small and you do not need a plugin.

 

$('a[href^="#"]').on('click', function(event) {
    var target = $(this.getAttribute('href'));
    if( target.length ) {
        event.preventDefault();
        $('html, body').stop().animate({
            scrollTop: target.offset().top
        }, 1000);
    }
});

 

Source: https://www.abeautifulsite.net/smoothly-scroll-to-an-element-without-a-jquery-plugin-2