2009-11-16 44 views

回答

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> 
+0

不錯 - 但事件只在圓圈的邊界上觸發。 (因爲它不是實心的圓形) – jantimon 2009-11-16 23:28:45

+0

用以下方式很容易修改:circ.attr('fill','red'); – SimonDever 2009-11-16 23:36:55

+0

嘿,非常感謝,它工作正常。 有沒有辦法將它包含到使用raphaeljs組件創建的小部件中? – suprasad 2009-11-17 01:06:15

相關問題