如何链接多个jquery fancybox?

时间:2011-03-24 15:45:54

标签: javascript jquery fancybox

我在我的网络应用程序中使用fancybox作为模态。

有些情况下我想打开第二个fancybox,而其中一个已经打开了。有谁知道这样做的方法?在另一个关闭之后,我可以打开一个,或者两个都在另一个打开的同时打开。

同样,我在我的应用程序中使用了jquery和fancybox。

2 个答案:

答案 0 :(得分:5)

这是一个很好的相关主题,讨论相同的事情。How do I open one Fancybox after another closes?

EDITED: 在讨论中,https://stackoverflow.com/users/139396/o-k-w

提供了一个很好的例子

我已将示例放在jsfiddle:http://jsfiddle.net/CkK8N/

答案 1 :(得分:1)

我自己刚刚解决了这个问题。

情景:

  • 使用iframe启动一个fancybox
  • 从打开的fancybox中打开另一个包含由ajax webservice提供的内容的fancybox。

关键点

  • 如果使用fancybox和iframe,则需要使用parent。$。fancybox,否则$ .fancybox将使用。
  • 不要忘记在加载内容之前显示活动
  • 加载内容后不要忘记调整大小

代码段:

        if (parent) {
        // if in an iframe we need to show activity for the parents' fancybox
        parent.$.fancybox.showActivity();
    }
    else {
        // otherwise show activity for the fancybox of the current window
        $.fancybox.showActivity();
    }       

            // I'm using Ajax to fetch the content but you can fetch it in other ways too
    $.ajax({
        url: "your url goes here",
        type: "POST",
        contenttype: "text/xml; charset=utf-8",
        dataType: "xml",
        data: { "name": "john"},
        success: function (data, textStatus, jqXHR) {

            if (parent) {                   
                // if in an iframe we need to push the content into the parents' fancybox
                parent.$.fancybox($(jqXHR.responseXML).text());
                parent.$.fancybox.resize();
            }
            else {
                // otherwise push the content into the fancybox of the current window
                $.fancybox($(jqXHR.responseXML).text());
                $.fancybox.resize();
            }

        }
    });