Created
June 21, 2012 18:24
-
-
Save jonkemp/2967570 to your computer and use it in GitHub Desktop.
scrollDown: Scrolls the page down to show an element if it is not currently in the viewport. Requires jQuery.
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
function scrollDown( options ) { | |
var settings, winHeight, elementTop; | |
// override settings by passing in the options object | |
settings = $.extend({ | |
'offset': 70, | |
'selector': 'footer', | |
'speed': 'fast' | |
}, options); | |
winHeight = $(window).scrollTop() + $(window).height() + settings.offset; | |
elementTop = $(settings.selector).offset().top + $(settings.selector).height(); | |
// scroll into view, if element is out of view | |
if ( elementTop > winHeight ) { | |
$('html, body').animate({ | |
scrollTop: elementTop - settings.offset | |
}, settings.speed ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment