Skip to content

Instantly share code, notes, and snippets.

@hettiger
Last active May 29, 2019 14:14
Show Gist options
  • Save hettiger/9035899 to your computer and use it in GitHub Desktop.
Save hettiger/9035899 to your computer and use it in GitHub Desktop.
Simple smooth scrolling with jQuery :-)
$(function () {
$("nav").find("a[href*=#]:not([href=#])").click(function () {
var offset = 0;
var speed = 1000;
var target = $(this.hash);
$("html,body").animate({
scrollTop: target.offset().top - offset
}, speed);
});
});
@sdaponte
Copy link

I'm getting a console error that says "Uncaught TypeError: Cannot read property 'top' of undefined". Any ideas on why this is happening?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment