Created
January 8, 2015 13:40
-
-
Save benhuson/7d0868a90b56e45f35fe to your computer and use it in GitHub Desktop.
100% height div across multiple browsers including mobile Safari.
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
/** | |
* 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