I have a a fixed element that is supposed to be centered in the screen. I also have input elements inside. As it should, when the inputs are focused on, the whole page with the fixed element moves around.
However, if the user hits the "Go" key or a button that I created which hides the whole fixed element and blurs the input, the next time I try to show the fixed element, it is still out of place (the page is back to normal). It shows slid halfway off the bottom of the screen (even though no input is focused and the keyboard is down).
Any help would be appreciated. I have been pulling my hair out about this. This is showing up in a PhoneGap project but I have replicated the issue using a standard website viewed through Mobile Safari.
Here is a bit of my code:
<!--(HTML)-->
<div class="smooth-button" onclick="show()">Show</div>
<div id="popin">
<input type="text" placeholder="Example!" />
<div class="smooth-button" onclick="save()">Save</div>
</div>
...
/* (CSS) */
#popin {
position: fixed;
left: 50%;
top: 50%;
height: 400px;
width: 300px;
margin-top: -200px; /*keeps it perfectly centered*/
margin-left: -150px; /*keeps it perfectly centered*/
}
#smooth-button {
/* make the div look like a cool button */
}
...
// (JavaScript)
function show() {
$("#popin").css('display', 'block');
}
function save() {
//code to save text
$("#popin").css('display', 'none');
}