Skip to content

Instantly share code, notes, and snippets.

@apajak
apajak / smoothscroll
Last active August 29, 2015 13:57
Creates a smooth scrolling. Based off http://tinyurl.com/smoothscrollingjs. Added features: Use the smooth scroll for only specific anchor tags, and keeps the #anchor name for future linking purposes.
var jump=function(e){
//prevent the "normal" behaviour which would be a "hard" jump
e.preventDefault();
//Get the target
var target = $(this).attr("href");
//perform animated scrolling
if(target =='#home' || target=='#about'|| target=='#portfolio' || target=='#contact'){
$('html,body').animate(
{
//get top-position of target-element and set it as scroll target