我是 RaphaelJS 的新手。我试图将点击监听器和键盘监听器添加到 Canvas 但没有成功。有人可以解释一下如何在 Raphael 上使用点击监听器和键盘监听器吗?一个小例子会有很大帮助。
谢谢。
最佳答案
这是一个点击和鼠标悬停示例,您可以在其中使用更多 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>
关于javascript - 我可以为 RaphaelJS 的 Canvas 事件提供点击和键盘处理程序吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1742917/