In CSS, I can do it like:
<div class="aspect-ratio-box"></div>
body {
max-width: 1366px;
margin: 0 auto;
padding: 20px;
}
.aspect-ratio-box {
height: 0;
padding-top: 56.25%;
background: red;
}
Here's the CodePen. Try resizing the browser window to see how it maintains aspect ratio.
But I can't wrap my head around on how to do it with Konva, especially React Konva where I have to maintain aspect ratio using width
, height
& aspectRatio
. There is no padding-top
.
How should I do it?
Note: It looks similar to How to resize images proportionally / keeping the aspect ratio? but I have tried this solution & it jumps up from original position (width=1024, height=600) when I shrink the browser but when I grow it again it never returns to the original position (width=1024, height=600)
This is what I want my app to look like:
Basically I want to accomplish the white part in the center in JS because I need to use Canvas.