Skip to main content

More Easing Functions Tutorial

This tutorial demonstrates all of the easing function sets provided by Konva, including:

  • Linear
  • Ease
  • Back
  • Elastic
  • Bounce
  • Strong

For all available easings go to Easings Documentation.

Instructions: Press "Play" to transition all of the text nodes 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',
'BackEaseIn',
'BackEaseOut',
'BackEaseInOut',
'ElasticEaseIn',
'ElasticEaseOut',
'ElasticEaseInOut',
'BounceEaseIn',
'BounceEaseOut',
'BounceEaseInOut',
'StrongEaseIn',
'StrongEaseOut',
'StrongEaseInOut',
];

const tweens = [];

easings.forEach((easing, i) => {
const text = new Konva.Text({
x: 50,
y: 30 + i \* 25,
text: easing,
fontSize: 16,
fontFamily: 'Calibri',
fill: 'black',
});
layer.add(text);

tweens.push(
new Konva.Tween({
node: text,
duration: 2,
x: width - 200,
easing: Konva.Easings[easing],
})
);
});

stage.add(layer);

// create button

const button = document.createElement('button');
button.textContent = 'Play';
button.addEventListener('click', () => {
tweens.forEach((tween) => {
tween.reset();
tween.play();
});
});
document.body.appendChild(button);


</rewritten_file>