Mobile Safari does not support position: fixed
when an input focused and virtual keyboard displayed.
To force it work the same way as Mobile Chrome, you have to use position: absolute
, height: 100%
for the whole page or a container for your pseudo-fixed elements, intercept scroll
, touchend
, focus
, and blur
events.
The trick is to put the tapped input control to the bottom of screen before it activates focus. In that case iOS Safari always scrolls viewport predictably and window.innerHeight
becomes exactly visible height.
Open https://avesus.github.io/docs/ios-keep-fixed-on-input-focus.html in Mobile Safari to see how it works.
Please avoid forms where you have several focusable elements because more tricks to fix position will be necessary, those were added just for demonstration purposes.
Note that for rotation and landscape mode, additional tricks are necessary. I'm working on a framework called Tuff.js which will provide a full-screen container helping mobile web developers to build web applications much faster. I've spend almost a year on the research.
By the way, to prevent scrolling of the whole window when virtual keyboard is active, you can use this super simple trick: https://codepen.io/WinterJoey/pen/WvwyqX