Skip to content

Instantly share code, notes, and snippets.

@sashasklar
Created February 8, 2011 23:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sashasklar/817535 to your computer and use it in GitHub Desktop.
Save sashasklar/817535 to your computer and use it in GitHub Desktop.
jQuery snippet for making an element "full screen" in mobile browsers. Includes hiding the address bar and silencing scroll events in jQuery Mobile.
(function($) {
$.maximize = function() {
var $body = $('body');
// prevent scrollstart and scrollstop events from fireing in jquery mobile
if ($.event.special.scrollstart) {
$.event.special.scrollstart.enabled = false;
}
// expand the body so there's enough room for the address bar to scroll out of view
$body.height(2 * window.innerHeight);
setTimeout(function() {
// scroll the window to hide the address bar
window.scrollTo(0, 0);
// shrink the body back down to window height
$body.height(window.innerHeight);
},20);
// resume scrollstart and scrollstop events
if ($.event.special.scrollstart) {
setTimeout(function() {
$.event.special.scrollstart.enabled = true;
}, 150 );
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment