HTML5 Canvas 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, rotation,
width, height, radius, strokeWidth, opacity, scaleX, offsetX, etc.

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

Konva Tweening Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/[email protected]/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Linear Easing 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();

var rect = new Konva.Rect({
x: 50,
y: 20,
width: 100,
height: 50,
fill: 'green',
stroke: 'black',
strokeWidth: 2,
opacity: 0.2,
});

layer.add(rect);
stage.add(layer);

// the tween has to be created after the node has been added to the layer
var tween = new Konva.Tween({
node: rect,
duration: 1,
x: 140,
y: 90,
fill: 'red',
rotation: Math.PI * 2,
opacity: 1,
strokeWidth: 6,
scaleX: 1.5,
});

// start tween after 2 seconds
setTimeout(function () {
tween.play();
}, 2000);
</script>
</body>
</html>
Enjoying Konva? Please consider to support the project.