jQuery 使用 AJAX 和 Fancybox 1.3 加载内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9843115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 11:22:39  来源:igfitidea点击:

Load content with AJAX and Fancybox 1.3

jqueryajaxfancybox

提问by user1048676

All, I'm trying to load some content into a fancybox. I'd like to load some page content using AJAX. How can I load this content into my fancybox using AJAX and version 1.3?

所有,我正在尝试将一些内容加载到fancybox中。我想使用 AJAX 加载一些页面内容。如何使用 AJAX 和 1.3 版将此内容加载到我的fancybox?

Thanks!

谢谢!

回答by Dan Ellis

To load AJAX content into FancyBox by clicking a link, you could use the following method, taken directly from the FancyBox examples (http://fancybox.net/howto):

要通过单击链接将 AJAX 内容加载到 FancyBox,您可以使用以下方法,直接取自 FancyBox 示例 ( http://fancybox.net/howto):

<a class="various" href="/demo/ajax.php">Ajax</a>

$(document).ready(function() {
    $(".various").fancybox();
});

Note this works perfectly but if you want to specify other parameters to the fancy box you can do following:

请注意,这非常有效,但如果您想为花式框指定其他参数,您可以执行以下操作:

 $(document).ready(function() {
    $(".various").fancybox({
        hideOnOverlayClick:false,
        hideOnContentClick:false,
        ....,
    });
});

For other parameters refer to the fancybox documentation.

其他参数请参考fancybox 文档。

You could always specify the hrefwithin the JavaScript by using the hrefoption (http://fancybox.net/api).

您始终可以href使用href选项 ( http://fancybox.net/api)在 JavaScript 中指定。

UPDATE:I see you're using 1.3.4 so links have been updated accordingly.

更新:我看到您使用的是 1.3.4,因此链接已相应更新。

UPDATE:If you were to update to FancyBox 2, you could use the following example from the FancyBox website (http://fancyapps.com/fancybox/#examples):

更新:如果您要更新到 FancyBox 2,您可以使用来自 FancyBox 网站 ( http://fancyapps.com/fancybox/#examples)的以下示例:

<a class="various fancybox.ajax" href="/demo/ajax.php">Ajax</a>

$(document).ready(function() {
    $(".various").fancybox({
        maxWidth    : 800,
        maxHeight   : 600,
        fitToView   : false,
        width       : '70%',
        height      : '70%',
        autoSize    : false,
        closeClick  : false,
        openEffect  : 'none',
        closeEffect : 'none'
    });
});

回答by Simon Edstr?m

Just taken from http://fancybox.net/which use 1.3

刚取自使用 1.3 的http://fancybox.net/

$("#Link").fancybox({
    ajax : {
        type    : "POST",
        data    : 'mydata=test'
    }
});

回答by gige

function test_function(){

     $.fancybox({
        'scrolling'         : 'no',
        'padding'           : 0,
        'centerOnScroll'    : true,
        'href'              : 'faq.php',
        'type'              : 'ajax'
     });
}