Because 100vh will be larger than the visible height when the URL bar is shown
. According to this.
You can calculate the height of the URL bar by creating a 0-width element with 100vh height.
<div id="control-height"></div>
#control-height {
height: 100vh;
width: 0;
position: absolute;
}
Then using javascript compare window.innerHeight
with the height of this element.
const actualHeight = window.innerHeight;
const elementHeight = document.getElementById('control-height').clientHeight;
const barHeight = elementHeight - actualHeight;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…