我是RaphaelJS的新手。我试图将单击侦听器和键盘侦听器添加到画布,但没有成功。有人可以解释如何在Raphael上使用点击监听器和键盘监听器。一个小例子将会有很大的帮助。
谢谢。
答案 0 :(得分:2)
这是一个click和mouseover示例,您可以在其中使用更多jQuery来简化它,但我只是想使用文档就绪功能。在那里添加键盘事件不应该太多:
<html>
<head>
<script type="text/javascript" src="http://github.com/DmitryBaranovskiy/raphael/blob/master/raphael-min.js?raw=true"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
var paper = new Raphael(document.getElementById('canvas_container'), 500, 500);
var circ = paper.circle(250, 250, 40);
circ.node.onmouseover = function()
{
this.style.cursor = 'pointer';
};
circ.node.onclick = function()
{
circ.animate({opacity: 0}, 2000, function()
{
this.remove();
});
}
});
</script>
<style type="text/css">
#canvas_container
{
width: 500px;
border: 1px solid #aaa;
}
</style>
</head>
<body>
<div id="canvas_container"></div>
</body>
</html>