abdullahtarawneh.com/static/scripts/mobileViewportHeight.js

19 lines
536 B
JavaScript
Raw Normal View History

2021-12-22 23:34:40 +00:00
var root = document.documentElement;
2021-12-22 23:14:41 +00:00
let vh = window.innerHeight * 0.01;
2021-12-22 23:34:40 +00:00
root.style.setProperty('--vh', `${vh}px`);
this.lastHeight = window.innerHeight;
2021-12-22 23:14:41 +00:00
2021-12-22 23:40:37 +00:00
/*
2021-12-22 23:14:41 +00:00
// We listen to the resize event
window.addEventListener('resize', () => {
// We execute the same script as before
2021-12-22 23:34:40 +00:00
if (
window.innerWidth > window.innerHeight ||
Math.abs(this.lastHeight - window.innerHeight) > 100
) {
let vh = window.innerHeight * 0.01;
root.style.setProperty('--vh', `${vh}px`);
this.lastHeight = window.innerHeight;
}
2021-12-22 23:16:17 +00:00
});
2021-12-22 23:40:37 +00:00
*/