Last active
December 17, 2015 09:19
-
-
Save justincarroll/5586118 to your computer and use it in GitHub Desktop.
Bloated smooth-scroll jQuery plugins beware! jQuery has the inherent ability to smooth-scroll the page to a certain location with one line of code. The more you know...
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title>jQuery Smooth Scroll Without a Plugin</title> | |
<style>p { height: 3000px; }</style> | |
<script src="http://code.jquery.com/jquery.js"></script> | |
<script src="script.js"></script> | |
</head> | |
<body> | |
<p><a id="scrollfrom" href="#">Click this to scroll!</a></p> | |
<h1 id="scrollto">Goodbye, world!</h1> | |
</body> | |
</html> |
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
$(document).ready( function() { | |
// Dynamically gets the scrollTop() value of an element and animates there | |
$( '#scrollfrom' ).click( function() { | |
$( 'body, html' ).animate( { scrollTop: jQuery( '#scrollto' ).offset().top }, 'slow' ); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment