Skip to content

Commit cee7fd9

Browse files
author
scottjehl
committed
prototyped version of scrolling using overflow touch. No support for fixed headers yet
1 parent 69583d1 commit cee7fd9

File tree

3 files changed

+45
-22
lines changed

3 files changed

+45
-22
lines changed

js/jquery.mobile.core.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@
9595

9696
// Scroll page vertically: scroll to 0 to hide iOS address bar, or pass a Y value
9797
silentScroll: function( ypos, elem ) {
98-
99-
var elem = elem && elem[ 0 ] || window;
100-
10198
if ( $.type( ypos ) !== "number" ) {
10299
ypos = $.mobile.defaultHomeScroll;
103100
}
@@ -106,7 +103,12 @@
106103
$.event.special.scrollstart.enabled = false;
107104

108105
setTimeout(function() {
109-
elem.scrollTo( 0, ypos );
106+
if( elem ){
107+
elem.scrollTop( ypos );
108+
}
109+
else{
110+
window.scrollTo( 0, ypos );
111+
}
110112
$( document ).trigger( "silentscroll", { x: 0, y: ypos });
111113
}, 20 );
112114

js/jquery.mobile.navigation.js

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -394,20 +394,28 @@
394394
toScroll = active.lastScroll || $.mobile.defaultHomeScroll,
395395
screenHeight = getScreenHeight();
396396

397-
// Scroll to top
398-
window.scrollTo( 0, $.mobile.defaultHomeScroll );
397+
if( $.support.overflowScrollingTouch && fromPage ){
398+
// Send focus to the newly shown page
399+
$.mobile.silentScroll( toScroll, toPage );
400+
}
401+
else{
402+
window.scrollTo( 0, $.mobile.defaultHomeScroll );
403+
}
399404

400405
//if the Y location we're scrolling to is less than 10px, let it go for sake of smoothness
401-
if( toScroll < $.mobile.minScrollBack ){
406+
if( toScroll < $.mobile.minScrollBack && !$.support.overflowScrollingTouch ){
402407
toScroll = 0;
403408
}
404409

405410
if( fromPage ) {
406411
//trigger before show/hide events
407412
fromPage.data( "page" )._trigger( "beforehide", null, { nextPage: toPage } );
408413
}
409-
toPage
410-
.height( screenHeight + toScroll )
414+
if( !$.support.overflowScrollingTouch){
415+
toPage.height( screenHeight + toScroll );
416+
}
417+
418+
toPage
411419
.data( "page" )._trigger( "beforeshow", null, { prevPage: fromPage || $( "" ) } );
412420

413421
//clear page loader
@@ -420,15 +428,21 @@
420428
promise = th( transition, reverse, toPage, fromPage );
421429

422430
promise.done(function() {
423-
//reset toPage height bac
424-
toPage.height( "" );
425431

426-
// Send focus to the newly shown page
427-
reFocus( toPage );
428432

429-
// Jump to top or prev scroll, sometimes on iOS the page has not rendered yet.
430-
$.mobile.silentScroll( toScroll );
433+
if( $.support.overflowScrollingTouch ){
434+
$.mobile.silentScroll( toScroll, toPage );
435+
}
436+
else{
437+
//reset toPage height bac
438+
toPage.height( "" );
439+
440+
// Send focus to the newly shown page
441+
reFocus( toPage );
431442

443+
// Jump to top or prev scroll, sometimes on iOS the page has not rendered yet.
444+
$.mobile.silentScroll( toScroll );
445+
}
432446
//trigger show/hide events
433447
if( fromPage ) {
434448
fromPage.height("").data( "page" )._trigger( "hide", null, { nextPage: toPage } );
@@ -445,18 +459,23 @@
445459
function getScreenHeight(){
446460
var orientation = jQuery.event.special.orientationchange.orientation(),
447461
port = orientation === "portrait",
448-
winMin = port ? 480 : 320,
449-
screenHeight = port ? screen.availHeight : screen.availWidth,
462+
winMin = port ? 460 : 300,
463+
screenHeight = port ? document.documentElement.clientHeight || screen.availHeight : screen.availWidth || document.documentElement.clientWidth,
450464
winHeight = Math.max( winMin, $( window ).height() ),
451465
pageMin = Math.min( screenHeight, winHeight );
452466

453467
return pageMin;
454468
}
469+
455470

456471
//simply set the active page's minimum height to screen height, depending on orientation
457472
function resetActivePageHeight(){
458-
$( "." + $.mobile.activePageClass ).css( "min-height", getScreenHeight() );
473+
$( "." + $.mobile.activePageClass ).css( ( $.support.overflowScrollingTouch ? "height" : "min-height" ), getScreenHeight() );
459474
}
475+
476+
// TEMP TEMP
477+
$.mobile.getScreenHeight = getScreenHeight;
478+
$.mobile.resetActivePageHeight = resetActivePageHeight;
460479

461480
//shared page enhancements
462481
function enhancePage( $page, role ) {
@@ -893,8 +912,8 @@
893912
}
894913

895914
// Set active item's lastScroll prop
896-
if( active ){
897-
active.lastScroll = $( window ).scrollTop();
915+
if( active && fromPage ){
916+
active.lastScroll = $( ( $.support.overflowScrollingTouch ? fromPage : window ) ).scrollTop();
898917
}
899918

900919
// Kill the keyboard.

themes/default/jquery.mobile.core.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
/* responsive page widths */
1313
.ui-mobile-viewport { margin: 0; overflow-x: hidden; -webkit-text-size-adjust: none; -ms-text-size-adjust:none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); }
1414

15-
.ui-mobile-overflow-scrolling .ui-mobile-viewport { overflow: hidden; }
1615

1716
/* "page" containers - full-screen views, one should always be in view post-pageload */
1817
.ui-mobile [data-role=page], .ui-mobile [data-role=dialog], .ui-page { top: 0; left: 0; width: 100%; min-height: 100%; position: absolute; display: none; border: 0; }
@@ -34,7 +33,10 @@
3433
.ui-loader h1 { font-size: 15px; text-align: center; }
3534
.ui-loader .ui-icon { position: static; display: block; opacity: .9; margin: 0 auto; width: 35px; height: 35px; background-color: transparent; }
3635

37-
.ui-mobile-overflow-scrolling .ui-page { overflow:hidden; -webkit-overflow-scrolling: touch; }
36+
.ui-mobile-overflow-scrolling .ui-page { overflow: auto; -webkit-overflow-scrolling: touch; }
37+
38+
.ui-mobile-overflow-scrolling .ui-page.ui-mobile-internal-scroll { overflow: hidden; }
39+
.ui-mobile-overflow-scrolling .ui-page.ui-mobile-internal-scroll .ui-content { overflow: auto; -webkit-overflow-scrolling: touch; }
3840

3941
/*fouc*/
4042
.ui-mobile-rendering > * { visibility: hidden; }

0 commit comments

Comments
 (0)