Skip to main content

HTML5 Canvas Transform and Resize events

Konva.Transformer object has special transform events that you can use in your app: transformstart, transform and transformend.

These events also will be triggered on attached node.

Instructions: Open console, try to transform, see logs

import Konva from 'konva';

const width = window.innerWidth;
const height = window.innerHeight;

const stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
});

const layer = new Konva.Layer();
stage.add(layer);

const rect = new Konva.Rect({
x: 50,
y: 50,
width: 100,
height: 100,
fill: 'yellow',
stroke: 'black',
draggable: true,
});
layer.add(rect);

const tr = new Konva.Transformer({
nodes: [rect],
});
layer.add(tr);

tr.on('transformstart', () => {
console.log('transform start');
});

tr.on('transform', () => {
console.log('transforming');
});

tr.on('transformend', () => {
console.log('transform end');
});

rect.on('transformstart', () => {
console.log('rect transform start');
});

rect.on('transform', () => {
console.log('rect transforming');
});

rect.on('transformend', () => {
console.log('rect transform end');
});