<!DOCTYPE html> <html> <head> <!-- USE DEVELOPMENT VERSION --> <scriptsrc="https://unpkg.com/[email protected]/konva.min.js"></script> <metacharset="utf-8" /> <title>Konva Stop Transform Demo</title> <style> body { margin: 0; padding: 0; overflow: hidden; background-color: #f0f0f0; } </style> </head>
<body> <divid="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 rect = new Konva.Rect({ x: 160, y: 60, width: 100, height: 90, fill: 'red', name: 'rect', stroke: 'black', draggable: true, }); layer.add(rect);
// create new transformer var tr = new Konva.Transformer(); layer.add(tr); tr.nodes([rect]); tr.on('transform', function(){ var width = rect.width() * rect.scaleX(); if (width > 200) { tr.stopTransform(); // reset visible width to 200 // so future transform is possible var scaleX = 200 / rect.width(); rect.scaleX(scaleX); } }); </script> </body> </html>
Enjoying Konva? Please consider to
support the project.