Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 7th, 2012  |  syntax: None  |  size: 0.99 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.   * Normalized hide address bar for iOS & Android
  3.   * (c) Scott Jehl, scottjehl.com
  4.   * MIT License
  5. */
  6. (function( win ){
  7.         var doc = win.document;
  8.        
  9.         // If there's a hash, or addEventListener is undefined, stop here
  10.         if( !location.hash && win.addEventListener ){
  11.                
  12.                 //scroll to 1
  13.                 window.scrollTo( 0, 1 );
  14.                 var scrollTop = 1,
  15.                         getScrollTop = function(){
  16.                                 return win.pageYOffset || doc.compatMode === "CSS1Compat" && doc.documentElement.scrollTop || doc.body.scrollTop || 0;
  17.                         },
  18.                
  19.                         //reset to 0 on bodyready, if needed
  20.                         bodycheck = setInterval(function(){
  21.                                 if( doc.body ){
  22.                                         clearInterval( bodycheck );
  23.                                         scrollTop = getScrollTop();
  24.                                         win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
  25.                                 }      
  26.                         }, 15 );
  27.                
  28.                 win.addEventListener( "load", function(){
  29.                         setTimeout(function(){
  30.                                 //at load, if user hasn't scrolled more than 20 or so...
  31.                                 if( getScrollTop() < 20 ){
  32.                                         //reset to hide addr bar at onload
  33.                                         win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
  34.                                 }
  35.                         }, 0);
  36.                 } );
  37.         }
  38. })( this );