I want to be able to create multiple container. For example, by clicking a button in a new tab, a new container will be created with a new ID and the ability to draw a shape in it.
<html>
<head>
<script src="https://unpkg.com/konva@8.3.12/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<button id="add-container">Add Container</button>
<div id="tabs">
<ul>
<li><a href="#tabs-1">container</a></li>
</ul>
<div id="tabs-1">
<div id="container"></div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>
<script>
var width = window.innerWidth;
var height = window.innerHeight;
var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});
var layer = new Konva.Layer();
var circle = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});
// add the shape to the layer
layer.add(circle);
// add the layer to the stage
stage.add(layer);
$( function() {
$( "#tabs" ).tabs();
} );
var count = 0
$("#add-container").click(()=>{
$(`<li><a href='#cnt-${count}'>Container-${count}</a></li>`)
.appendTo("#tabs ul");
$(`<div id='cnt-${count}'>Container-${count}</div>`).appendTo("#tabs");
$("#tabs").tabs("refresh");
count++
})
</script>
</body>
</html>
Something like this. But there must be the ability to draw shapes in each container, for example by using drag and drop in each container. I did this in my project but I can't figure out which container they should be drawn in. Can you think of a solution?