Last active
August 29, 2015 14:24
-
-
Save nateperry/b6490f1369eb5e5fd421 to your computer and use it in GitHub Desktop.
Simple jQuery Scroller
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
/* | |
* Simple jQuery Scroller | |
* Uses jQuery to animate scrolling on click | |
* Simply use the ID that you want to scroll to | |
* as the href attribute of an <a> tag | |
* | |
* Example HTML: <a href="#main" class="scroll-to">Scroll to #main</a> | |
* | |
*/ | |
$(document).ready(function () { | |
// add event listener | |
$('.scroll-to').on('click', function (e) { | |
e.preventDefault(); | |
var id = $(e.currentTarget).attr('href') | |
var target = $(id); | |
$('html,body').animate({ | |
scrollTop: (target.offset().top) | |
}, 1000); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment