Created
February 8, 2011 23:39
-
-
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.
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
(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