feat: preserve ratio
This commit is contained in:
parent
7a7bd84f4b
commit
9fc749fdad
|
@ -12,13 +12,16 @@
|
|||
margin: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
body {
|
||||
.app {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
}
|
||||
.app, canvas {
|
||||
height: 100%;
|
||||
line-height: 0;
|
||||
width: 100%;
|
||||
}
|
||||
canvas {
|
||||
margin: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -107,3 +107,16 @@ if (module.hot) {
|
|||
renderer.destroy();
|
||||
});
|
||||
}
|
||||
// Make sure dis boi always correct ratio and always maximally visible.
|
||||
function onResize() {
|
||||
const ratio = window.innerWidth / window.innerHeight;
|
||||
const axe = ratio > (16 / 9) ? 'height' : 'width';
|
||||
const nodes = window.document.querySelectorAll('.app canvas');
|
||||
nodes.forEach((node) => {
|
||||
for (const key of ['height', 'width']) {
|
||||
node.style[key] = key === axe ? '100%' : 'auto';
|
||||
}
|
||||
});
|
||||
}
|
||||
window.addEventListener('resize', onResize);
|
||||
onResize();
|
||||
|
|
Loading…
Reference in New Issue
Block a user