Skip to content

Instantly share code, notes, and snippets.

@kaanon
Created September 4, 2013 07:21
Show Gist options
  • Save kaanon/6433713 to your computer and use it in GitHub Desktop.
Save kaanon/6433713 to your computer and use it in GitHub Desktop.
Scroll To
$('a.scroll').click(function (event) {
event.preventDefault();
var full_url = this.href;
var parts = full_url.split("#");
var trgt = parts[1];
if (trgt && $("#" + trgt).length) {
var target_offset = $("#" + trgt).offset();
var target_top = target_offset.top - 100;
$('html, body').animate(
{scrollTop: target_top}, //properties to animate
{
duration: 500,
complete: function () {}
}
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment