【问题标题】:Opening a link from a Raphael node into a lightbox打开从 Raphael 节点到灯箱的链接
【发布时间】:2010-09-10 09:51:47
【问题描述】:

我使用 fancybox 来满足我的灯箱需求。

我需要打开来自 raphael 元素的链接(在此演示中为 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",
        });
    },
...

所以我尝试了几种方法来设置链接的样式。一种天真的尝试是简单地将 test 的 id 添加到 attr。

我还尝试了以下方法:

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

而且它们都不起作用。该链接始终作为新链接打开,而不是在花哨的框中。

我做错了什么,我需要做些什么来纠正它?

【问题讨论】:

    标签: javascript fancybox raphael


    【解决方案1】:

    修复它。

    我没有使用 href 属性,而是直接从节点的 onclick 处理程序中调用了 fancybox,给了我这个:

        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");
            }
        };
    

    哪个有效!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多