Created
July 10, 2013 15:48
-
-
Save brettsnippets/5967450 to your computer and use it in GitHub Desktop.
Smooth Scroll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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