On mobile (e.g. Chrome on Android) the viewport height changes depending on whether the URL/Address bar is hidden or not, which changes depending on whether you're scrolling up or down on the page.
Given this, I need 2 variables:
In other words: "min" and "max" viewport heights. How would I go about doing that? I only know how to get:
By doing: Math.max(document.documentElement.clientHeight, window.innerHeight || 0)
(source: https://stackoverflow.com/a/8876069/473368).
For this, use the window.outerHeight
property:
Window.outerHeight
gets the height in pixels of the whole browser window. It represents the height of the whole browser window including sidebar (if expanded), window chrome and window resizing borders/handles.
To expand your function, just compare window.outerHeight
and window.innerHeight
:
let maxHeight = Math.max(window.innerHeight || 0, window.outerHeight || 0);
let minHeight = Math.min(window.innerHeight || 0, window.outerHeight || 0);
console.log(maxHeight, minHeight);