Created
July 20, 2012 00:10
-
-
Save silentrob/3147818 to your computer and use it in GitHub Desktop.
Scroll to position
This file contains hidden or 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
$('.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