improved the address bar hiding logic to support Android as well by determining up-front which hiding number should be used. Fixes #1673. Fixes #1322. Fixes #1786.

This commit is contained in:
scottjehl 2011-06-19 13:53:27 -04:00
parent ca0c1165fd
commit a09c53eb71
3 changed files with 18 additions and 3 deletions

View file

@ -96,7 +96,10 @@
//scroll page vertically: scroll to 0 to hide iOS address bar, or pass a Y value
silentScroll: function( ypos ) {
ypos = ypos || 0;
if( $.type( ypos ) !== "number" ){
ypos = $.mobile.defaultHomeScroll;
}
// prevent scrollstart and scrollstop events
$.event.special.scrollstart.enabled = false;

View file

@ -106,5 +106,17 @@
//window load event
//hide iOS browser chrome on load
//check which scrollTop value should be used by scrolling to 1 immediately
//then check what the scroll top is. Android will report 0... others 1
//note that this initial scroll won't hide the address bar. It's just for the check.
window.scrollTo( 0, 1 );
//if defaultHomeScroll hasn't been set yet, see if scrollTop is 1
//it should be 1 in most browsers, but android treats 1 as 0 (for hiding addr bar)
//so if it's 1, use 0 from now on
$.mobile.defaultHomeScroll = ( !$.support.scrollTop || $(window).scrollTop() === 1 ) ? 0 : 1;
//call silentScroll on load to hide addr bar
$window.load( $.mobile.silentScroll );
})( jQuery, this );

View file

@ -388,11 +388,11 @@
//get current scroll distance
var currScroll = $window.scrollTop(),
toScroll = toPage.data( "lastScroll" ) || 0;
toScroll = toPage.data( "lastScroll" ) || $.mobile.defaultHomeScroll;
//if scrolled down, scroll to top
if( currScroll ){
window.scrollTo( 0, 0 );
window.scrollTo( 0, $.mobile.defaultHomeScroll );
}
//if the Y location we're scrolling to is less than 10px, let it go for sake of smoothness