HTML5 Canvas Remove Event Listener with Konva

To remove an event listener with Konva, we can use the off() method of
a shape object which requires an event type such as click or mousedown.

Instructions: Click on the circle to see an alert triggered from the onclick
event binding. Remove the event listener by clicking on the button and again
click on the circle to observe that the event binding has been removed.

Konva Remove_Event Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.rawgit.com/konvajs/konva/1.7.6/konva.min.js"></script>
<meta charset="utf-8">
<title>Konva Remove Event Listener Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #F0F0F0;
}
#buttons {
position: absolute;
top: 5px;
left: 10px;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="buttons">
<button id="removeClick">
Remove onclick
</button>
</div>
<script>
function writeMessage(message) {
text.setText(message);
layer.draw();
}

var stage = new Konva.Stage({
container: 'container',
width: 300,
height: 300
});

var layer = new Konva.Layer();

var circle = new Konva.Circle({
x: stage.getWidth() / 2,
y: stage.getHeight() / 2 + 10,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4
});

circle.on('click', function() {
alert('You clicked on the circle');
});

layer.add(circle);
stage.add(layer);

document.getElementById('removeClick').addEventListener('click', function() {
circle.off('click');
alert('onclick removed');
}, false);
</script>

</body>
</html>