Javascript 听Raphael.js右键单击svg元素
当用户右键单击使用Rapahel.js创建的元素时,我需要做出响应。我读到您应该附加一个click事件处理程序,然后决定用户单击了哪个鼠标按钮。我不能让它工作Javascript 听Raphael.js右键单击svg元素,javascript,svg,raphael,Javascript,Svg,Raphael,当用户右键单击使用Rapahel.js创建的元素时,我需要做出响应。我读到您应该附加一个click事件处理程序,然后决定用户单击了哪个鼠标按钮。我不能让它工作 <!DOCTYPE html> <html> <head> <script src="http://raphaeljs.com/raphael.js"></script> <script> window.onload = function() {
<!DOCTYPE html>
<html>
<head>
<script src="http://raphaeljs.com/raphael.js"></script>
<script>
window.onload = function() {
var r = Raphael('demo', 640, 480);
r.rect(10, 10, 400, 400).attr({fill: 'red'}).click(function(){
alert('test');
});;
};
</script>
</head>
<body>
<div id="demo"></div>
</body>
</html>
但也请阅读以下内容:
是的,这也有效,但只适用于jQuery,而且最好不要使用.node,
由于Raphael有时会重新创建节点,因此会丢失事件处理程序
您可以使用
mousedown
并测试e.which
。这适用于FF和Chrome:
var r = Raphael('demo', 640, 480);
r.rect(10, 10, 400, 400).attr({fill: 'red'}).mousedown(function(e){
if (e.which == 3)
alert("hi")
});
对于跨浏览器解决方案,您可能还需要查看e.button
:谢谢。当你了解他们时,答案似乎很简单:)
var r = Raphael('demo', 640, 480);
r.rect(10, 10, 400, 400).attr({fill: 'red'}).mousedown(function(e){
if (e.which == 3)
alert("hi")
});