<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/konva@7.2.5/konva.min.js"></script> <meta charset="utf-8" /> <title>Konva Resize Text Demo</title> <style> body { margin: 0; padding: 0; overflow: hidden; background-color: #f0f0f0; } </style> </head>
<body> <div id="container"></div> <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(); stage.add(layer);
var rect1 = new Konva.Rect({ x: 50, y: 60, width: 100, height: 100, draggable: true, fill: 'green', stroke: 'black', strokeWidth: 5, }); layer.add(rect1);
var tr1 = new Konva.Transformer({ nodes: [rect1], ignoreStroke: true, padding: 5, }); layer.add(tr1);
rect1.on('transform', () => { rect1.setAttrs({ width: Math.max(rect1.width() * rect1.scaleX(), 5), height: Math.max(rect1.height() * rect1.scaleY(), 5), scaleX: 1, scaleY: 1, }); });
var rect2 = new Konva.Rect({ x: 250, y: 60, width: 100, height: 100, draggable: true, fill: 'red', stroke: 'black', strokeWidth: 5, strokeScaleEnabled: false, }); layer.add(rect2);
var tr2 = new Konva.Transformer({ nodes: [rect2], ignoreStroke: true, padding: 5, }); layer.add(tr2);
layer.draw(); </script> </body> </html>
|