Last active
August 29, 2015 13:57
-
-
Save apajak/9649257 to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
scrollTop: $(target).offset().top | |
//scrolldelay: 2 seconds | |
},1000,function() | |
{ | |
//attach the hash (#jumptarget) to the pageurl | |
location.hash = target; | |
}); | |
}else{ | |
} | |
} | |
$(document).ready(function() | |
{ | |
$('a[href*=#]').bind("click", jump); | |
return false; | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment