Firstly, I'm well aware that this question has been asked before but there's never been a solution to fix the issue across all devices.
It's been asked at vh / % units and keyboard on mobile devices , Ignore or disable mobile viewport resize due to keyboard open for text inputs on mobile web? , and Android Keyboard shrinking the viewport and elements using unit vh in CSS.
I have researched this and tried a few JavaScript & jQuery methods but I can't seem to find a solution that works.
When the keyboard opens in mobile it shrinks the height of the viewport, text and inputs that have been sized with vh
all get shorter. I need a way of calculating the initial page viewport height when it loads and then sticking with that height even if the viewport shrinks so that all page items are the same height as if the keyboard wasn't there.
Below is an example of how the inputs look before and after keyboard activation then to the right there's an example of the desired behaviour. I'd like to base vh
on the initial height of the viewport for mobile as headers, text, icons and inputs are all sized via vh
.
Any help would be appreciated.
EDIT
This question was originally posted on October 30th 2019. This update is being added on July 15th 2020 now that I've had time to look into these briefly after remembering this question a week or so ago. Microsoft's switch to Chromium has been beneficial in many ways but has now caused Chrome to acknowledge this properly with their latest announcement under the heading of Scrolling
How virtual keyboards affect - or don't affect - viewport units in different browsers. (Note recent work from Microsoft Edge on a VirtualKeyboard API that may help here.)
You can read the blog post titled Improving Chromium's browser compatibility in 2020 by clicking it and more about Intent to Prototype: VirtualKeyboard API by clicking that too. Hopefully this helps someone who finds this question in the future.