JSFiddle - React, Tailwind, and code Playground
by bighostkim
HTML
<div id="container"></div>
CSS
body {
margin: 0px;
padding: 0px;
}
canvas {
border: 1px solid #9C9898;
}
JavaScript
var stage = new Kinetic.Stage({
container: "container",
width: 578,
height: 200
});
var layer = new Kinetic.Layer();
var colors = ["red", "orange", "yellow", "green", "blue", "purple"];
for(var n = 0; n < 6; n++) {
// anonymous function to induce scope
(function() {
var i = n;
var box = new Kinetic.Rect({
x: i * 30 + 150,
y: i * 18 + 40,
fill: colors[i],
stroke: "black",
strokeWidth: 4,
draggable: true,
name: "name"+n,
width: 100,
height: 50
});
box.on("dragstart", function() {
box.moveToTop();
layer.draw();
});
box.on("dragmove", function() {
document.body.style.cursor = "pointer";
});
/*
* dblclick to remove box for desktop app
* and dbltap to remove box for mobile app
*/
box.on("dblclick dbltap", function() {
layer.remove(box);
layer.draw();
});
box.on("mouseover", function() {
document.body.style.cursor = "pointer";
});
box.on("mouseout", function() {
document.body.style.cursor = "default";
});
layer.add(box);
})();
}
stage.add(layer);
layer.on('dblclick', function(evt) {
var shape = evt.shape;
name = shape.getName();
alert(name);
});