Skip to content

Instantly share code, notes, and snippets.

@andredublin
Created January 15, 2012 01:13
Show Gist options
  • Save andredublin/1613741 to your computer and use it in GitHub Desktop.
Save andredublin/1613741 to your computer and use it in GitHub Desktop.
Sometimes localscroll doesn't work for me, so I made this function to do simply vertical navigation
$navLinks.click(function(event) {
var pos1, pos2, hash, start, end, total, time,
$this = $(this),
offset = $($this.attr('href')).offset().top,
pos1 = $this.offset().top,
hash = event.currentTarget.hash.toString(),
pos2 = $(hash.toString()).offset().top,
$target = $('html, body');
start = parseInt(pos1);
end = parseInt(pos2);
total = start - end;
time = Math.abs(total);
$target.animate({scrollTop:offset}, time, 'easeInOutQuint');
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment