stage.on('click tap', function(e){ // if click on empty area - remove all transformers if (e.target === stage) { stage.find('Transformer').destroy(); layer.draw(); return; } // do nothing if clicked NOT on our rectangles if (!e.target.hasName('rect')) { return; } // remove old transformers // TODO: we can skip it if current rect is already selected stage.find('Transformer').destroy();
// create new transformer var tr = new Konva.Transformer(); layer.add(tr); tr.attachTo(e.target); layer.draw(); }); </script> </body> </html>