打开fancybox的同时打开另一个fancybox实例 [英] Open a fancybox while another instance of fancybox is open

查看:101
本文介绍了打开fancybox的同时打开另一个fancybox实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户单击按钮时,我会显示一个花哨框,指示用户应等待操作完成:

When the user clicks on a button i show a fancybox that indicates that user should wait till the action is completed:

jQuery(document).ready(function () {
             $.fancybox('Please Wait...',{'modal':true});
        });

现在我通过$ .post函数检查请求的操作并返回结果消息(操作成功或操作失败的错误),现在我想关闭第一个fancybox并显示带有响应的新fancybox.来自ajax:

now i check the requested action via $.post function and return the result message (either action was successful or the error why the action failed) and now i want to close the first fancybox and show the new fancybox with the response i got from ajax:

$.post('someurl.aspx',{'somethingtopost':'value'},
function(data){
jQuery(document).ready(function () {
$.fancybox(data);
         });
     }
);

问题是第二个fancybox没有显示.有很多示例在关闭第一个fancybox时显示第二个fancybox(添加到onClosed属性),但是在此示例中,我不想在关闭第一个fancybox时显示第二个fanybox,我想在操作时显示它完成.

The problem is the second fancybox doesn't show. there are many examples on showing a second fancybox when closing the first one (adding to onClosed attribute) but as in this one I don't want to show the second fanybox after closing the first one, I want to show it when the action is completed.

推荐答案

您可以随时触发第二个Fancybox,而不管是否已经打开了它(并且无需先关闭它).只需在操作完成后尝试发射第二个Fancybox.

You can trigger a second Fancybox any time regardless that there is one already opened (and without closing it first). Just try firing a second Fancybox when the action is completed.

第二个Fancybox窗口(一旦触发)将替换第一个,而无需任何其他关闭命令.

The second Fancybox window (once is triggered) will replace the first one without any further closing command.

function openFancybox() {
    setTimeout( function() {$('#delayed').trigger('click'); },10000);
}
$(document).ready(function() {
    $('#pageLoad').fancybox({
        helpers: {overlay:{opacity: 0.3}}
    }).click();
    openFancybox();
    $('#delayed').fancybox({
        helpers: {overlay:{opacity: 0.3}}
    });
}); // ready

我设置了一个此处的示例页面,该页面在加载页面时启动Fancybox,然后10秒后会发射第二个Fancybox.

I set an example page here that starts Fancybox on page load, then it fires a second Fancybox after 10 seconds.

第一个Fancybox会在第二个被发射后自动关闭.

The first Fancybox closes automatically after the second is fired.

更新

或者您可能更喜欢此版本

function openFancybox() {
    setTimeout( function() {$('#delayed').trigger('click'); },10000);
}
$(document).ready(function() {
    $('#goProcess').click(function(){
        $.fancybox({
            href: '#wait',
            modal: true,
            helpers: {overlay:{opacity: 0.3}},
            afterLoad: function() {
                openFancybox();
            }
        }); // fancybox
    });
    $('#delayed').fancybox({
        helpers: {overlay:{opacity: 0.3}}
    });
}); // ready

在单击按钮时打开fancybox,然后在10秒后触发第二个fancybox (或在后台处理完成之后.)

Open fancybox on a button click, then triggers a second fancybox after 10 seconds (or after a process in the background is completed.)

这篇关于打开fancybox的同时打开另一个fancybox实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆