Skip to content

Instantly share code, notes, and snippets.

@brettsnippets
Created July 10, 2013 15:48
Show Gist options
  • Save brettsnippets/5967450 to your computer and use it in GitHub Desktop.
Save brettsnippets/5967450 to your computer and use it in GitHub Desktop.
Smooth Scroll
var smooth = {
Scroll: function(item, speed) {
// when the item is clicked
item.click(function() {
// grab the html document and / or the body
$("html, body").animate({
// grab the item clicked's href and get the distance between this element
//and the element it is scrolling to
scrollTop: $($(this).attr("href")).offset().top + "px"
}, {
duration: speed,
easing: "swing"
});
return false;
});
} // end of scroll
}; // end of smooth object literal
// runs the function using these links or buttons
smooth.Scroll($('#toContact'), 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment