Gesture Events on Canvas Shapes

How to listen to swipe, pinch zoom, rotate and other multi-touch gesture events on canvas shapes?

By default Konva supports only basic touch events such as touchstart, touchmove, touchend.

You have to implement gesture events manually from that touch events.

If you are looking for pan and zoom logic for the whole stage take a look into Multi-touch scale Stage demo.

But I was able to slightly change Hammer.js to make it work with Konva!

You can find modified hammer.js source code here.

Instructions: you can try different gestures on the rectangle such as swipe, rotate, zoom, drag&drop, press.

For desktop browsers you can hold Shift key to emulate touch events.

Note: this demo is experimental.

Konva Touch Gestures Demoview raw
<!DOCTYPE html>
<script src="[email protected]/konva.min.js"></script>
<!-- emulate touches on desktop -->
<script src=""></script>
<!-- 3-rd party library for gesture events -->
<script src="/js/hammer-konva.js"></script>

<meta charset="utf-8" />
<title>Konva Touch Gestures Demo</title>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
<div id="container"></div>
Konva.hitOnDragEnabled = true;
Konva.captureTouchEventsEnabled = true;

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 originalAttrs = {
x: stage.width() / 2,
y: stage.height() / 2,
scaleX: 1,
scaleY: 1,
draggable: true,
rotation: 0,

var group = new Konva.Group(originalAttrs);

var size = 200;

var rect = new Konva.Rect({
width: size,
height: size,
fill: 'yellow',
offsetX: size / 2,
offsetY: size / 2,
cornerRadius: 5,
shadowBlur: 10,
shadowColor: 'grey',

var defaultText = 'Try\ndrag, swipe, pinch zoom, rotate, press...';
var text = new Konva.Text({
text: defaultText,
x: -size / 2,
width: size,
align: 'center',

// attach modified version of Hammer.js
// "domEvents" property will allow triggering events on group
// instead of "hammertime" instance
var hammertime = new Hammer(group, { domEvents: true });

// add rotate gesture
hammertime.get('rotate').set({ enable: true });

// now attach all possible events
group.on('swipe', function (ev) {
x: group.x() + ev.evt.gesture.deltaX,
y: group.y() + ev.evt.gesture.deltaY,

onFinish: function () {{}, originalAttrs));

group.on('press', function (ev) {
text.text('Under press');{
fill: 'green',

group.on('touchend', function (ev) {{
fill: 'yellow',

setTimeout(() => {
}, 300);

group.on('dragend', () => {{}, originalAttrs));

var oldRotation = 0;
var startScale = 0;
group.on('rotatestart', function (ev) {
oldRotation = ev.evt.gesture.rotation;
startScale = rect.scaleX();

group.on('rotate', function (ev) {
var delta = oldRotation - ev.evt.gesture.rotation;
oldRotation = ev.evt.gesture.rotation;
group.scaleX(startScale * ev.evt.gesture.scale);
group.scaleY(startScale * ev.evt.gesture.scale);

group.on('rotateend rotatecancel', function (ev) {{}, originalAttrs));
Enjoying Konva? Please consider to support the project.