Skip to content

Instantly share code, notes, and snippets.

@cyaenorama
Forked from brettsnippets/smooth.js
Created August 19, 2017 07:52
Show Gist options
  • Select an option

  • Save cyaenorama/84a3f212e3aa060bbaf14a56d125812b to your computer and use it in GitHub Desktop.

Select an option

Save cyaenorama/84a3f212e3aa060bbaf14a56d125812b 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