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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user