Permalink
Browse files

first.

  • Loading branch information...
0 parents commit 0871b48caf6190ed490923886842874f4945309b scottjehl committed Jan 6, 2012
Showing with 64 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +9 −0 README.md
  3. +16 −0 demo.html
  4. +34 −0 hide-address-bar.js
@@ -0,0 +1,5 @@
+.project
+*~
+*.diff
+*.patch
+.DS_Store
@@ -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
@@ -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>
@@ -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 );
tschaub
tschaub Dec 11, 2012

Could be win here instead.

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.