I'm trying to make a rectangle responsive based on the width of the window.
This is my current logic:
aspectRatio = 16 / 9
win = {
width: window.innerWidth,
height: window.innerHeight,
}
get browser() {
const width = this.win.width - 250
const height = width / this.aspectRatio
return {
width,
height,
}
}
To calculate the width
, I subtract the sidebar width (250) from win.width
.
For the height
, I divide the width
by the aspectRatio
.
However, when the window size is reduced to around 700px, it results in a height of 0.
My application can be seen here:
https://i.stack.imgur.com/rqpVc.png
Demo →
CodeSandBox → https://codesandbox.io/s/add-padding-to-centered-canvas-with-sidebar-gqhhl
I want the papayawhip rectangle to be responsive. What algorithm should I use? I'm using Canvas with KonvaJS but the logic is written in JavaScript.
How can I make it responsive and maintain proportionality as the height shortens quickly?