Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 26d53cd

Browse files
committed
Panel: ScrollTop only when ui-content is out of view
Fixes #6767 Closes #8483
1 parent 2f00774 commit 26d53cd

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

js/helpers.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,24 @@ $.extend( $.mobile, {
255255
this.loading._widget = loader;
256256

257257
return returnValue;
258+
},
259+
260+
isElementCurrentlyVisible: function( el ) {
261+
el = typeof el === "string" ? $( el )[ 0 ] : el[ 0 ];
262+
263+
if( !el ) {
264+
return true;
265+
}
266+
267+
var rect = el.getBoundingClientRect();
268+
269+
return (
270+
rect.bottom > 0 &&
271+
rect.right > 0 &&
272+
rect.top <
273+
( window.innerHeight || document.documentElement.clientHeight ) &&
274+
rect.left <
275+
( window.innerWidth || document.documentElement.clientWidth ) );
258276
}
259277
} );
260278

js/widgets/panel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ return $.widget( "mobile.panel", {
216216
( heightWithMargins - heightWithoutMargins ) );
217217
}
218218
}
219-
if ( scrollToTop === true ) {
219+
if ( scrollToTop === true &&
220+
!$.mobile.isElementCurrentlyVisible( ".ui-content" ) ) {
220221
this.window[ 0 ].scrollTo( 0, $.mobile.defaultHomeScroll );
221222
}
222223
} else {

0 commit comments

Comments
 (0)