Skip to main content

Basic Tweening Tutorial

To tween properties with Konva, we can instantiate a Konva.Tween object and then start the tween by calling play(). Any numeric property of a Shape, Group, Layer, or Stage can be transitioned, such as:

  • x, y (position)
  • rotation
  • width, height, radius
  • strokeWidth
  • opacity
  • scaleX, scaleY
  • offsetX, offsetY

For a full list of attributes and methods, check out the Konva.Tween documentation.

Instructions: Click the circle to start a simple linear animation.

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();

const circle = new Konva.Circle({
x: 100,
y: height / 2,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
});

layer.add(circle);
stage.add(layer);

circle.on('click tap', () => {
// simple tween

const tween = new Konva.Tween({
node: circle,
duration: 1,
x: width - 100,
easing: Konva.Easings.Linear,
});
tween.play();
});


</rewritten_file>