var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
// Does a scroll target exist?
if (target.length) {
// Only prevent default if animation is actually gonna happen
event.preventDefault();
$('html, body').animate({
scrollTop: target.offset().top
}, 1000, function() {
// Callback after animation
// Must change focus!
var $target = $(target);
$target.focus();
if ($target.is(":focus")) { // Checking if the target was focused
return false;
} else {
$target.attr('tabindex','-1'); // Adding tabindex for elements not focusable
$target.focus(); // Set focus again
};
});
}
}
});
////////////////////////Native browser smooth scrolling is like this/////////////////////////
// Scroll to specific values
// scrollTo is the same
// Select all links with hashes
// Remove links that don't actually link to anything
// Figure out element to scroll to
// Only prevent default if animation is actually gonna happen
});
////////////////////////Native browser smooth scrolling is like this///////////////////////// // Scroll to specific values // scrollTo is the same
// Scroll certain amounts from current position
// Scroll to a certain element
http://iamdustan.com/smoothscroll/ https://css-tricks.com/snippets/jquery/smooth-scrolling/