apolineaire
5/31/2018 - 7:08 AM

Smooth Scroll to an ID

From Tania Rascia

$("a[href^='#']").click(function(e) {
	e.preventDefault();
	
	var position = $($(this).attr("href")).offset().top;

	$("body, html").animate({
		scrollTop: position
	} /* speed */ );
});


/*ANOTHER VERSION FROM https://www.abeautifulsite.net/smoothly-scroll-to-an-element-without-a-jquery-plugin-2 */

$('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);
            }
        });