From fa667f0c1488b4addb8ca8930446fb5edd96ac28 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Wed, 12 Jun 2013 09:02:09 +0530 Subject: [PATCH] Improve the scroll to view port logic Do minimal scroll when top of the window is out of view Change-Id: I8a2eb01451961655b651d53763356bd7e0aa5abf --- src/jquery.uls.core.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/jquery.uls.core.js b/src/jquery.uls.core.js index 30549cb..0d3cfd0 100644 --- a/src/jquery.uls.core.js +++ b/src/jquery.uls.core.js @@ -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