Improve the scroll to view port logic

Do minimal scroll when top of the window is out of view

Change-Id: I8a2eb01451961655b651d53763356bd7e0aa5abf
This commit is contained in:
Santhosh Thottingal
2013-06-12 09:02:09 +05:30
parent 5f2b646c42
commit fa667f0c14

View File

@@ -430,21 +430,20 @@
$.fn.scrollIntoView = function () {
return this.each( function () {
var scrollPosition,
padding = 10,
$window = $( window ),
windowHeight = $window.height(),
windowScrollTop = $window.scrollTop(),
windowBottom = windowScrollTop + windowHeight,
windowTop = $window.scrollTop(),
windowBottom = windowTop + windowHeight,
$element = $( this ),
panelHeight = $element.height(),
panelTop = $element.offset().top,
panelBottom = panelTop + panelHeight;
if ( ( panelTop < windowScrollTop ) || ( panelBottom > windowBottom ) ) {
if ( panelHeight > windowHeight ) {
scrollPosition = panelTop - padding;
if ( ( panelTop < windowTop ) || ( panelBottom > windowBottom ) ) {
if ( windowTop > panelTop ) {
scrollPosition = panelTop;
} else {
scrollPosition = panelBottom - windowHeight + padding;
scrollPosition = panelBottom - windowHeight;
}
$( 'html, body' ).stop().animate( {
scrollTop: scrollPosition