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

Panel: ScrollTop only when ui-content is out of view #8483

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,24 @@ $.extend( $.mobile, {
this.loading._widget = loader;

return returnValue;
},

isElementCurrentlyVisible: function( el ) {
el = typeof el === "string" ? $( el )[ 0 ] : el[ 0 ];

if( !el ) {
return true;
}

var rect = el.getBoundingClientRect();

return (
rect.bottom > 0 &&
rect.right > 0 &&
rect.top <
( window.innerHeight || document.documentElement.clientHeight ) &&
rect.left <
( window.innerWidth || document.documentElement.clientWidth ) );
}
} );

Expand Down
3 changes: 2 additions & 1 deletion js/widgets/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ return $.widget( "mobile.panel", {
( heightWithMargins - heightWithoutMargins ) );
}
}
if ( scrollToTop === true ) {
if ( scrollToTop === true &&
!$.mobile.isElementCurrentlyVisible( ".ui-content" ) ) {
this.window[ 0 ].scrollTo( 0, $.mobile.defaultHomeScroll );
}
} else {
Expand Down