Created
March 12, 2012 16:50
-
-
Save tsvensen/2023290 to your computer and use it in GitHub Desktop.
jQuery ScrollTo
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
// ScrollTo top of an element | |
$('html, body').animate({scrollTop: $('#my-element').offset().top}, 600, 'linear'); | |
// ScrollTo and center the element | |
$('html, body').animate({ | |
scrollTop: parseInt($('#my-element').offset().top) - ($(window).height() / 2) + ($('#my-element').height() / 2), | |
scrollLeft: parseInt($('#my-element').offset().left) - ($(window).width() / 2) + ($('#my-element').width() / 2) | |
}, 600, 'linear'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment