Created
April 5, 2011 15:53
-
-
Save shawnchin/903887 to your computer and use it in GitHub Desktop.
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
/* scroll page so obj is visible in current view with | |
* a _minimum_ bottom margin of "bottom_margin" (default:20). | |
* -- requires jQuery -- | |
*/ | |
function scroll_to(obj, bottom_margin, speed) { | |
bottom_margin = bottom_margin || 20; | |
var target_height = obj.height() + bottom_margin; | |
var visible_height = $(window).height(); | |
var scroll_top = obj.offset().top; | |
if (target_height < visible_height) { | |
scroll_top += target_height - visible_height; | |
} | |
$('html').animate({scrollTop:scroll_top}, (speed)? speed : "fast"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment