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.
<!DOCTYPE html> <html> <head> <scriptsrc="https://unpkg.com/[email protected]/konva.min.js"></script> <metacharset="utf-8" /> <title>Konva Linear Easing 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();
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, });