2012-07-27 109 views
0

我創建了一個3D圓圈並希望它可以點擊並顯示其數據。我似乎無法讓它工作。有人可以幫助我弄清楚這一點嗎?在那裏我嘗試這樣做是接近底部的代碼....用Raphael製作一個可點擊的物體JS

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html lang="en"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <title>Raphaël · Ball</title> 
    <link rel="stylesheet" href="demo.css" type="text/css" media="screen"> 
    <link rel="stylesheet" href="demo-print.css" type="text/css" media="print"> 
    <script src="raphael.js" type="text/javascript" charset="utf-8"></script> 
    <script type="text/javascript" charset="utf-8"> 
     Raphael.fn.ball = function (x, y, r, hue) { 
      hue = hue || 0; 
      return this.set(
       //this part is the drop shadow 
       this.ellipse(x, y + r - r/5, r, r/2).attr({fill: "rhsb(" + hue + ", 1, .25)-hsb(" + hue + ", 1, .25)", stroke: "none", opacity: 0}), 
       //this part is the top part of the circle 
       this.ellipse(x, y, r, r).attr({fill: "r(.5,.9)hsb(" + hue + ", 1, .75)-hsb(" + hue + ", .5, .25)", stroke: "none"}), 
       //this is the inner glow part from the top 
       this.ellipse(x, y, r - r/5, r - r/20).attr({stroke: "none", fill: "r(.5,.1)#ccc-#ccc", opacity: 0}) 
      ); 
     }; 
     window.onload = function() { 
      var R = Raphael("holder"), x = 300, y = 100, r = 100; 
      //I cant tell what numbers are passed into here????? 
      R.ball(x, y, r, Math.random()).data("i", i).click(function() { 
      alert(this.data("i")); 
     }); 
     }; 
    </script> 
    </head> 
    <body> 
     <div id="holder"></div> 
    </body> 
</html> 

回答

0

我道歉,如果我拿錯在這裏...但是這個代碼的樣本爲我工作的罰款....不幸的是我似乎找不到var i在你的代碼中,你傳遞給data('i',i) ....聲明var i = something;或試試這個數據('我','你好')讓你知道它的作品...希望它有幫助。

jsFiddle

+0

後它的jsfiddle如果你可以... – 2012-07-27 20:13:01

+0

你應該嘗試什麼我建議.....你只需要聲明一個變種我在你的代碼....完蛋了。 ... – Aukhan 2012-07-27 20:58:01