跳到主要内容

基本补间教程

如需使用 Konva 对属性执行补间,可以创建 Konva.Tween 对象,然后调用 play() 开始补间。 任何 ShapeGroupLayerStage 的数值属性均可过渡,例如:

  • xy(位置)
  • rotation
  • widthheightradius
  • strokeWidth
  • opacity
  • scaleXscaleY
  • offsetXoffsetY

如需查看完整的属性和方法列表,请参阅 Konva.Tween 文档

操作说明:单击圆形,启动简单的线性动画。

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