Skip to content

Instantly share code, notes, and snippets.

@bguiz
Created November 22, 2013 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bguiz/7594363 to your computer and use it in GitHub Desktop.
Save bguiz/7594363 to your computer and use it in GitHub Desktop.
Workaround for bug in iOS5+ where `position: fixed;` behaves incorrectly when virtual keyboard is opened Solution somewhat similar to: http://stackoverflow.com/a/15537846/194982 Presently simply hides/ shows anything with class 'myFixed' (e.g. a header bar), but may be modified to do fancier things like repositioning it manually with JavaScript…
function workaroundIosFixedPositionBug() {
var isIosSafari = /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
if (isIosSafari) {
// workaround for bug in iOS5+ where `position: fixed;` behaves incorrectly when virtual keyboard is opened
// Solution somewhat similar to: http://stackoverflow.com/a/15537846/194982
// Presently simply hides/ shows anything with class 'myFixed' (e.g. a header bar), but may be modified to do
// fancier things like repositioning it manually with javascript, should that be a requirement
$('#main').on("focus", "input, textarea", function() {
$('.myFixed').css('display', 'none');
});
$('#main').on("blur", "input, textarea", function() {
$('.myFixed').css('display', 'block');
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment