HTML5 Canvas Mobile Scrolling and Native Events with Konva

By default Konva will prevent default behaviour off all pointer interactions with a stage.
That will prevent unexpected scrolling of a page when you are trying to drag&drop a shape on a mobile device.

But in some cases you may want to keep default behaviour of browser events. In that case you may set preventDefault property of a shape to false.

Instructions: if you are on mobile device try to scroll a page by each rectangle.
Green - should prevent default behaviour (no page scrolling).
Red - will keep default behaviour (scrolling should work).

Konva Mobile Scrolling Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/[email protected]/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva Mobile Scrolling and Native Events 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 defaultBehaviourRect = new Konva.Rect({
width: 100,
height: 100,
fill: 'green',
});
layer.add(defaultBehaviourRect);

var noPreventDefaultRect = new Konva.Rect({
x: 200,
y: 50,
width: 100,
height: 100,
fill: 'red',
preventDefault: false,
});

layer.add(noPreventDefaultRect);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>
Enjoying Konva? Please consider to support the project.