现在我在玩KonvaJS。我click
在shape
. 当我单击 时shape
,将调用侦听器。在我的听众中,我正在调用event.preventDefault()
方法来停止触发其他事件。但是当我这样做时,它会说:
未捕获的 TypeError:event.preventDefault 不是函数
我不知道我错过了什么。这是我的代码:
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.rawgit.com/konvajs/konva/0.9.5/konva.min.js"></script>
<meta charset="utf-8">
<title>Konva Scale Animation 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();
stage.add(layer);
var gArrow2 = new Image();
var circle2 = new Konva.Image({
x: 60, //on canvas
y: 60,
image: gArrow2,
name: 'abc',
id: 'xyz',
draggable:true
});
circle2.on('click',function(event){
event.preventDefault()
console.log(e.type);
});
circle2.on('mouseup',function(event){
event.preventDefault()
console.log(e.type);
});
gArrow2.onload = function() {
layer.add(circle2);
layer.draw();
}
gArrow2.src = 'http://konvajs.github.io/assets/snake.png';
var period = 1500;
var amplitude = 10;
var centerX = stage.getWidth() / 2;
var centerY = stage.getHeight() / 2;
var anim = new Konva.Animation(function(frame) {
circle2.setY(amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerY);
}, layer);
anim.start();
</script>
</body>
</html>