Skip to content

Instantly share code, notes, and snippets.

@benhuson
Created January 8, 2015 13:40
Show Gist options
  • Save benhuson/7d0868a90b56e45f35fe to your computer and use it in GitHub Desktop.
Save benhuson/7d0868a90b56e45f35fe to your computer and use it in GitHub Desktop.
100% height div across multiple browsers including mobile Safari.
/**
* 100% height div across multiple browsers including mobile Safari.
* http://www.ethanhackett.com/?blog=window-height-100-on-mobile-safari-coding-solution
*/
( function( $, window, undefined ) {
// First check to see if the platform is an iPhone, iPod, iPad (mobile Safari)
if ( /iP/.test( navigator.platform ) && /Safari/i.test( navigator.userAgent ) ) {
var mobileSafari = "Safari";
}
// Set the div height
function set100PercentHeight( element ) {
var new_height = $(this).height();
// if mobileSafari add +60px
if ( typeof mobileSafari === 'string' ) { new_height += 60; };
element.css( 'height', new_height );
}
// Resize Elements
set100PercentHeight( $( '#supersized' ) );
$( window ).resize( function() {
set100PercentHeight.call( this, $( '#supersized' ) );
} );
} ( jQuery, this ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment