jbutko
8/12/2013 - 11:26 AM

jQuery: smooth scroll to desired #element

jQuery: smooth scroll to desired #element

//HTML MARKUP

<a href="#services">Jump to services</a>

<div id="services">

</div>


//jQuery
$(document).ready(function(){
  $('a[href^="#"]').on('click',function (e) {
	    e.preventDefault();

	    var target = this.hash,
	    $target = $(target);

	    $('html, body').stop().animate({
	        'scrollTop': $target.offset().top
	    }, 900, 'swing', function () {
	        window.location.hash = target;
	    });
	});
});