Skip to main content

Simple Easings Tutorial

To create a non-linear easing tween with Konva, we can set the easing property to an easing function. Other than Konva.Easings.Linear, the other most common easings are:

  • Konva.Easings.EaseIn
  • Konva.Easings.EaseInOut
  • Konva.Easings.EaseOut

For all available easings go to Easings Documentation.

Instructions: Mouseover or touchstart the boxes to tween them with different easing functions.

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 easings = ['Linear', 'EaseIn', 'EaseOut', 'EaseInOut'];
const boxes = [];

easings.forEach((easing, i) => {
const box = new Konva.Rect({
x: 50,
y: 50 + i \* 80,
width: 100,
height: 50,
fill: '#00D2FF',
stroke: 'black',
strokeWidth: 4,
});
layer.add(box);
boxes.push(box);

const text = new Konva.Text({
x: 160,
y: 65 + i \* 80,
text: easing,
fontSize: 16,
fontFamily: 'Calibri',
fill: 'black',
});
layer.add(text);

box.on('mouseenter touchstart', () => {
const tween = new Konva.Tween({
node: box,
duration: 1,
x: width - 150,
easing: Konva.Easings[easing],
}).play();
});

box.on('mouseleave touchend', () => {
const tween = new Konva.Tween({
node: box,
duration: 1,
x: 50,
easing: Konva.Easings[easing],
}).play();
});
});

stage.add(layer);


</rewritten_file>