2010-09-10 55 views
2

我爲燈箱需要使用fancybox打開從拉斐爾節點到燈箱的鏈接

我需要打開一個raphael元素的鏈接(在此演示中,a circle)。

通常你會創建一個鏈接和風格它像這樣:

<a id="test" href="ajax.html">Click Me</a></li> 
<script type="text/javascript"> 
$(document).ready(function() { 
    $('#test').fancybox({ 
     'width'   : '75%', 
     'height'   : '75%', 
     'autoScale'  : false, 
     'transitionIn' : 'none', 
     'transitionOut' : 'none', 
     'type'   : 'iframe' 
    }); 

要東西的圈子是在它自己的JavaScript文件,該文件是的fancybox後宣佈複雜的是:

<script src="./fancybox/jquery.fancybox-1.3.1.pack.js" type="text/javascript"></script> 
<script src="demo02.js" type="text/javascript" charset="utf-8"></script> 

刪節版本的demo02.js看起來像:

var Demo = { 
    initialize: function() { 
     var dim = this.getWindowDimensions(); 
     this.paper = Raphael("canvas", dim.width, dim.height); 
     // set events 
     (document.onresize ? document : window).onresize = function() { 
      Demo.resize(); 
     } 

     // add circle 
     var circle = this.paper.circle(150, 120, 100); 
     circle[0].style.cursor = "pointer"; 
     circle.attr({ 
      fill: "green", 
      stroke: "#333", 
      "stroke-width": 10, 
      href: "ajax.html", 
     }); 
    }, 
... 

所以我嘗試了幾種方式e鏈接。一個天真的嘗試是簡單地將測試的id添加到attr。

我也試過如下:

$(circle.node).fancybox({ 
$('circle.node').fancybox({ 
$('#circle.node').fancybox({ 
$('#canvas.circle.node').fancybox({ 
$('#Demo.circle.node').fancybox({ 

,沒有他們的工作。該鏈接始終作爲新鏈接打開,而不是花哨框。

我在做什麼錯,我需要做些什麼來糾正它?

回答

1

修正了它。

除了使用href屬性的,我直接調用的fancybox從onclick處理程序中的節點給我這個:

var circle = this.paper.circle(150, 120, 100); 
    circle[0].style.cursor = "pointer"; 
    circle.attr({ 
     fill: "green", 
     stroke: "#333", 
     "stroke-width": 10, 
    }); 
    circle.node.onclick = function() { 
     $.fancybox({ 
      'href'   : 'ajax.html', 
      'width'   : '75%', 
      'height'  : '75%', 
      'autoScale'  : false, 
      'transitionIn' : 'none', 
      'transitionOut' : 'none', 
      'type'   : 'iframe' 
     }); 

     if (circle.attr("fill") == "red") { 
      circle.attr("fill", "green"); 
     } else { 
      circle.attr("fill", "red"); 
     } 
    }; 

其中一期工程!