JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://www.html5canvastutorials.com/libraries/kinetic-v4.0.5.js"></script>
<div id="canvas-wrapper"></div>
CSS
#canvas-wrapper {
width: 600px;
height: 600px;
}
JavaScript
$(function() {
initStage();
});
function initStage() {
window.stage = new Kinetic.Stage({
container: 'canvas-wrapper',
width: $('#canvas-wrapper').width(),
height: $('#canvas-wrapper').height(),
});
window.layer = new Kinetic.Layer();
window.thingGroup = new Kinetic.Group({
x: 140,
y: 100,
draggable: true
});
layer.add(thingGroup);
stage.add(layer);
// Create the boxes
addBox(50,50, 'red');
addBox(200,200, 'blue');
// Rescale all boxes to 1
window.stage.getContainer().addEventListener('click', function(e) {
$.each(window.layer.get('.box'), function(index, box) {
box.setScale(1);
console.log('clicked on stage');
});
});
}
function addBox(xPos, yPos, color) {
var box = new Kinetic.Rect({
x: xPos,
y: yPos,
width: 150,
height: 150,
stroke: "#000",
fill: color,
strokeWidth: 0,
draggable: true,
name: 'box'
});
box.on('click', function() {
box.setScale(2);
$.each(window.layer.get('.box'), function(index, boxx) {
if(boxx != box) {
boxx.setScale(1);
}
});
});
window.thingGroup.add(box);
window.stage.draw();
}