Skip to content

Instantly share code, notes, and snippets.

@Joseph-N
Last active August 29, 2015 13:57
Show Gist options
  • Save Joseph-N/9366552 to your computer and use it in GitHub Desktop.
Save Joseph-N/9366552 to your computer and use it in GitHub Desktop.
With this jquery snippet you will be able to animate to an anchor from a url. If for example you follow a link from page A (e.g http://mywebsite.com/products/1#tomato) it will scroll smoothly to the element with id of tomato in page B
// animate scroll put this on (PAGE B)
var elementClick = window.location.hash
var destination = $(elementClick).offset().top;
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100, function() {
window.location.hash = elementClick
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment