Skip to content

Commit

Permalink
first.
Browse files Browse the repository at this point in the history
  • Loading branch information
scottjehl committed Jan 6, 2012
0 parents commit 0871b48
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
@@ -0,0 +1,5 @@
.project
*~
*.diff
*.patch
.DS_Store
9 changes: 9 additions & 0 deletions README.md
@@ -0,0 +1,9 @@
A normalized approach to hiding the address bar on iOS and Android
=======================

Authored by @scottjehl

MIT License.

Read this article for explanation
http://24ways.org/2011/raising-the-bar-on-mobile
16 changes: 16 additions & 0 deletions demo.html
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test page</title><title>Cross-device Address Bar Hide - Example 1</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="hide-address-bar.js"></script>
<style>
/* DEMO ONLY for this short page - remove in live code */
body { min-height: 480px; }
</style>
</head>
<body>
<p>The script on this page should hide the address bar on iOS and Android.</p>
</body>
</html>
34 changes: 34 additions & 0 deletions hide-address-bar.js
@@ -0,0 +1,34 @@
/*! Normalized address bar hiding for iOS & Android (c) @scottjehl MIT License */
(function( win ){
var doc = win.document;

// If there's a hash, or addEventListener is undefined, stop here
if( !location.hash && win.addEventListener ){

//scroll to 1
window.scrollTo( 0, 1 );

This comment has been minimized.

Copy link
@tschaub

tschaub Dec 11, 2012

Could be win here instead.

This comment has been minimized.

Copy link
@scottjehl

scottjehl Dec 11, 2012

Owner

right. thanks!

var scrollTop = 1,
getScrollTop = function(){
return win.pageYOffset || doc.compatMode === "CSS1Compat" && doc.documentElement.scrollTop || doc.body.scrollTop || 0;
},

//reset to 0 on bodyready, if needed
bodycheck = setInterval(function(){
if( doc.body ){
clearInterval( bodycheck );
scrollTop = getScrollTop();
win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
}
}, 15 );

win.addEventListener( "load", function(){
setTimeout(function(){
//at load, if user hasn't scrolled more than 20 or so...
if( getScrollTop() < 20 ){
//reset to hide addr bar at onload
win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
}
}, 0);
} );
}
})( this );

0 comments on commit 0871b48

Please sign in to comment.