我们可以使用 on()
绑定多重事件,事件类型用空格分隔。
说明:鼠标滑过圆形观察 Mouseover、mousedown、 mouseup 事件的执行。
Konva Multi_Event Demoview raw<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/[email protected]/konva.min.js"></script> <meta charset="utf-8" /> <title>Konva Multi-Event Binding Demo</title> <style> body { margin: 0; padding: 0; overflow: hidden; background-color: #f0f0f0; } </style> </head>
<body> <div id="container"></div> <script> function writeMessage(message) { text.text(message); layer.draw(); }
var stage = new Konva.Stage({ container: 'container', width: window.innerWidth, height: window.innerHeight });
var layer = new Konva.Layer();
var text = new Konva.Text({ x: 10, y: 10, fontFamily: 'Calibri', fontSize: 20, text: '', fill: 'black' });
var numEvents = 0;
var circle = new Konva.Circle({ x: stage.width() / 2, y: stage.height() / 2 + 10, radius: 70, fill: 'red', stroke: 'black', strokeWidth: 4 });
circle.on('mouseover mousedown mouseup', function() { writeMessage('Multi-event binding! Events: ' + ++numEvents); }); circle.on('mouseout', function() { writeMessage(''); });
layer.add(circle); layer.add(text);
stage.add(layer); </script> </body> </html>
|