How to auto-resize canvas within a flex item?
See original GitHub issueThis is similar to the “how do I make Kanva responsive”, but it’s a bit of a different issue.
This is essentially what I have:
<div style="display: flex">
<div style="flex-shrink: 0">---</div>
<div style="flex-grow: 1" class="waveform">(Konva stage drawn here)</div>
<div style="flex-shrink: 0">---</div>
</div>
The issue is, when I resize my window, the .waveform
div shrinks accordingly since it’s a flex item, but since there’s a Konva div & canvas inside with a set width of (for example) 800px, the .waveform
div won’t shrink, resulting in this:
So I can’t use stage.width()
to set the new .waveform
offsetWidth
because it’s not actually changing. How do I make this Konva stage responsive within a flex item?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to make a HTML5 canvas fit dynamic parent/flex box ...
The current approach is CSS based where the canvas is re-sized according to the parent flex box element. The graphics are blurred, re...
Read more >CSS resize property - W3Schools
Here, the user can resize both the height and width of a <div> element: ... The numbers in the table specify the first...
Read more >Responsive Charts - Chart.js
Important Note. Detecting when the canvas size changes can not be done directly from the canvas element. Chart.js uses its parent container to ......
Read more >Object Fit - Tailwind CSS
Containing an element. Resize an element's content to stay contained within its container using .object-contain . <div class="bg-purple-300 .
Read more >Autoresize PIXI.autoDetectRenderer to size of parent element
Autoresize PIXI. ... December 5, 2016 in Pixi.js ... <div id="canvas-pane" class="flex-item flex-container flex-container-vertical"> <div ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am not 100% sure what is flex behavior here. Probably it is not getting smaller, because Stage is using the space.
In a similar issue I did this:
position: relative
to the parent of the stage..waveform
in your case.position: absolute; width: 100%
for stage container.Nice!