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 () {
|
$.fn.scrollIntoView = function () {
|
||||||
return this.each( function () {
|
return this.each( function () {
|
||||||
var scrollPosition,
|
var scrollPosition,
|
||||||
padding = 10,
|
|
||||||
$window = $( window ),
|
$window = $( window ),
|
||||||
windowHeight = $window.height(),
|
windowHeight = $window.height(),
|
||||||
windowScrollTop = $window.scrollTop(),
|
windowTop = $window.scrollTop(),
|
||||||
windowBottom = windowScrollTop + windowHeight,
|
windowBottom = windowTop + windowHeight,
|
||||||
$element = $( this ),
|
$element = $( this ),
|
||||||
panelHeight = $element.height(),
|
panelHeight = $element.height(),
|
||||||
panelTop = $element.offset().top,
|
panelTop = $element.offset().top,
|
||||||
panelBottom = panelTop + panelHeight;
|
panelBottom = panelTop + panelHeight;
|
||||||
|
|
||||||
if ( ( panelTop < windowScrollTop ) || ( panelBottom > windowBottom ) ) {
|
if ( ( panelTop < windowTop ) || ( panelBottom > windowBottom ) ) {
|
||||||
if ( panelHeight > windowHeight ) {
|
if ( windowTop > panelTop ) {
|
||||||
scrollPosition = panelTop - padding;
|
scrollPosition = panelTop;
|
||||||
} else {
|
} else {
|
||||||
scrollPosition = panelBottom - windowHeight + padding;
|
scrollPosition = panelBottom - windowHeight;
|
||||||
}
|
}
|
||||||
$( 'html, body' ).stop().animate( {
|
$( 'html, body' ).stop().animate( {
|
||||||
scrollTop: scrollPosition
|
scrollTop: scrollPosition
|
||||||
|
|||||||
Reference in New Issue
Block a user