![Get the height of the viewport](https://javascriptsource.com/wp-content/uploads/2022/12/Get-the-height-of-the-viewport-702x526.jpg)
There are two methods to get the viewport height: window.innerHeight
and document.documentElement.clientHeight
. The former is more accurate. The latter has better browser support.
To get the best of both worlds, try innerHeight
first, and fallback to clientHeight
if not supported.
var viewportHeight = window.innerHeight || document.documentElement.clientHeight;
Source
https://vanillajstoolkit.com/reference/viewport/viewport-height/