screen styling when virtual keyboard is active
Have JavaScript apply a class to the body when an input element has focus
.
$("input, textarea").focus(function(){ $(document.body).addClass('when-keyboard-showing'); });
$("input, textarea").blur( function(){ $(document.body).removeClass('when-keyboard-showing'); });
And then use @media
queries to determine if mobile view:
@media (max-width:550px) {
body.when-keyboard-showing .header { height:0; padding:0; }
}
The combination will let you stylize the page when the keyboard is up, on mobile. Thank you.
I'm not sure, is this the desired effect?. check this link
http://jsfiddle.net/UHdCw/3/
Update
(1). Assuming its a website & running on device browser. Then we can check the presence of virtual keyboard by checking the screen size.
Check in device browser - http://jsfiddle.net/UHdCw/8/show/
code : - http://jsfiddle.net/UHdCw/8/
(2). If you are building native app with HTML5 & Phonegap, things will be different. Since there is no direct API hook to check the keybord status, we have to write our own plugin in Phonegap.
In Android you can check show/hide status of keyboard by using native code [check here]. and have to write Phonegap plugin to get those events in our HTML.
[Phonegap is an example. I think most of the html to native frameworks have this kind of felicity to hook with native code ]
iOS update
As you said there is no change in height/position when keyboard is present. We can do one thing, when input gets the focus we can add shrink class and reduce the element sizes. Check following link.
http://jsfiddle.net/UHdCw/28/show/
I encountered the same problem, this works for me:
<!-- Android Viewport height fix-->
<script type="text/javascript">
var isAndroid = navigator.userAgent.toLowerCase().indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
document.write('<meta name="viewport" content="width=device-width,height='+window.innerHeight+', initial-scale=1.0">');
}
</script>