线性补间动画

获取Konva最新的信息

我们实例化Konva.Tween对象创建补间动画,然后执行play()运行动画。
任何数值类型的参数都可以用于补间动画, 比方说 Shape,Group, Layer, 或者 Stage 的数值型属性: x, y, rotation,
width, height, radius, strokeWidth, opacity, scaleX, offsetX 等等。

点击Konva.Tween documentation查询详细的参数和方法。

Konva Tweening Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/konva@4.0.18/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>