I have a fixed header, of which has a handful of links. Now, this code is almost where I need it to be to work, the main issue being that there's a delay when executing the second function. It does it's intended purpose of scrolling to the top of the page when the bound element is clicked, but it does so slowly at first, before continuing at the specified speed. I'm sure there's also a way to DRY this up and turn it into a single function instead of two separate ones. Any help would be greatly appreciated.
$(function() {
$("[href^='#']").on("click", function( e ) {
$("body, html").animate({
scrollTop: $( $(this).attr('href') ).offset().top-$('.header').height()-$('.header').outerHeight()
}, 800);
e.preventDefault();
});
});
$(function(){
$("#home").on("click", function( e ){
$("body, html").animate({
scrollTop: 0
}, 800);
e.preventDefault();
});
});
JSFiddle - http://jsfiddle.net/9by4n5cu/1/