javascript - 我可以为 RaphaelJS 的 Canvas 事件提供点击和键盘处理程序吗?

标签 javascript onclick raphael

我是 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/

相关文章:

javascript - 使用 node.js 模块,在什么情况下模块会执行两次?

javascript - 如何构建 3D 圆环图

javascript - 从 XML 生成的 JSON 中 "@attributes"元素的来源

javascript - React - 将 ref 传递给 sibling

wpf - WPF中的可点击ItemsControl项

javascript - 在 React 中将 DIV 的选择和状态管理为单选按钮选项

javascript - Raphael 中线条路径的宽度是 2px 而不是 1px

javascript - 单击时 JQuery 移动按钮样式更改

javascript - 莫里斯 donut chart 表没有数据问题

javascript - 我如何(有点)在 Canvas 内均匀分布动态大小的 SVG 形状?