Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
scottjehl
committed
Jan 6, 2012
0 parents
commit 0871b48
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.project | ||
*~ | ||
*.diff | ||
*.patch | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
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 ); |
Could be
win
here instead.