Skip to content

Commit a9196f3

Browse files
committed
Panel: ScrollTop only when ui-content is out of view
Fixes jquery-archive#6767 Closes jquery-archive#8483
1 parent 9a2daa0 commit a9196f3

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
@@ -230,6 +230,24 @@ $.extend( $.mobile, {
230230
this.loading._widget = loader;
231231

232232
return returnValue;
233+
},
234+
235+
isElementCurrentlyVisible: function( el ) {
236+
el = typeof el === "string" ? $( el )[ 0 ] : el[ 0 ];
237+
238+
if( !el ) {
239+
return true;
240+
}
241+
242+
var rect = el.getBoundingClientRect();
243+
244+
return (
245+
rect.bottom > 0 &&
246+
rect.right > 0 &&
247+
rect.top <
248+
( window.innerHeight || document.documentElement.clientHeight ) &&
249+
rect.left <
250+
( window.innerWidth || document.documentElement.clientWidth ) );
233251
}
234252
} );
235253

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)