Skip to content

Instantly share code, notes, and snippets.

@silentrob
Created July 20, 2012 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silentrob/3147818 to your computer and use it in GitHub Desktop.
Save silentrob/3147818 to your computer and use it in GitHub Desktop.
Scroll to position
$('.btt a[href*=#]').bind("click", $.NS.navigationJump);
$.NS = function(){
$(document).ready(function(){
try {
if(location.hash.length > 0){
var target = location.hash.split('/')[1];
var of = (target == "header") ? 0 : 350;
$('html, body').animate({scrollTop: $('#'+target).offset().top + of}, 500);
$('.nav a[href=#'+target+']').addClass('active');
}
} catch(e) { location.hash = ''; }
});
return {
navigationJump: function(e){
e.preventDefault();
$('.nav .active').removeClass('active');
$(this).addClass('active');
var target = $(this).attr('href');
console.log(target)
$('html, body').animate({
scrollTop: $(target).offset().top
}, 250, function(){
location.hash = '#/'+target.split('#')[1];
});
}
}
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment