question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to auto-resize canvas within a flex item?

See original GitHub issue

This 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:

Screenshot_2020-08-22 Tracks ReelCrafter

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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lavrtoncommented, Aug 24, 2020

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:

  1. add position: relative to the parent of the stage. .waveform in your case.
  2. use position: absolute; width: 100% for stage container.
  3. Update the stage size of container width.
0reactions
lavrtoncommented, Aug 24, 2020

Nice!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found