Shadowbox - 如何切换或替换内容?如何关闭和打开另一个对话框?

发布于 2024-12-14 07:03:08 字数 1265 浏览 2 评论 0原文

我尝试在多种场合使用 Shadowbox:有时我碰巧同时需要多个对话框。

在这个简单的示例中,我尝试关闭一个现有窗口并重新打开另一个窗口,但没有打开第二个窗口。我做错了什么?

<!DOCTYPE HTML>
<html>
<head>
    <link rel="stylesheet" href="shadowbox.css" type="text/css">
    <style type="text/css" media="screen">
        #sb-body, #sb-loading { background:#eee; }
    </style>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.js"></script>
    <script src="shadowbox.js" type="text/javascript" charset="utf-8"></script>

    <script type="text/javascript">

        Shadowbox.init();

        window.onload = function(){

            Shadowbox.open({
                content: 'First window. <a id="open-second" href="http://www.google.com">open another window</a>.',
                player: "html"
            });

            $('#open-second').live('click', function(e){
                e.preventDefault();

                Shadowbox.close();
                Shadowbox.open({
                    content: 'Second window.',
                    player: "html"
                });
            });
        };
    </script>
</head>
<body>blabla.</body>
</html>

问候,
阿迪特

I'm trying to use shadowbox in multiple occasions: sometimes I happen to need more than one dialog at the same time.

In this simple example I try to close one existing window and re-open another one but is not opening the second one. What I'm doing wrong?

<!DOCTYPE HTML>
<html>
<head>
    <link rel="stylesheet" href="shadowbox.css" type="text/css">
    <style type="text/css" media="screen">
        #sb-body, #sb-loading { background:#eee; }
    </style>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.js"></script>
    <script src="shadowbox.js" type="text/javascript" charset="utf-8"></script>

    <script type="text/javascript">

        Shadowbox.init();

        window.onload = function(){

            Shadowbox.open({
                content: 'First window. <a id="open-second" href="http://www.google.com">open another window</a>.',
                player: "html"
            });

            $('#open-second').live('click', function(e){
                e.preventDefault();

                Shadowbox.close();
                Shadowbox.open({
                    content: 'Second window.',
                    player: "html"
                });
            });
        };
    </script>
</head>
<body>blabla.</body>
</html>

Regards,
Adit

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一场春暖 2024-12-21 07:03:09

抱歉,但我想我会转向 colorbox,因为它看起来更稳定:

$('#second-btn').live('click', function(e){
  e.preventDefault();
  $.colorbox({
    onComplete: function(){
      $('#cboxLoadedContent').append('second opened');
      $('#cboxClose').attr('id', 'cboxClose_disabled');
    },
    html:'<p>Second <a id="first-btn" href="x">first</a></p>',
    width: 500, height: 200
  });
});

function showfirst(){
  $.colorbox({
    onLoad: function(){ $('#cboxClose_disabled').attr('id', 'cboxClose'); },
    onComplete: function(){ $('#cboxLoadedContent').append('first opened') },
    html:'<p>First <a id="second-btn" href="x">second</a></p>',
    width: 500, height: 200
  });
}

$('#first-btn').live('click', function(e){
  e.preventDefault();
  showfirst()
});

showfirst();

嘿,我是在一个人说话吗?! XD

Sorry 'bout this, but I think I'll move towards colorbox as it seems far more stable:

$('#second-btn').live('click', function(e){
  e.preventDefault();
  $.colorbox({
    onComplete: function(){
      $('#cboxLoadedContent').append('second opened');
      $('#cboxClose').attr('id', 'cboxClose_disabled');
    },
    html:'<p>Second <a id="first-btn" href="x">first</a></p>',
    width: 500, height: 200
  });
});

function showfirst(){
  $.colorbox({
    onLoad: function(){ $('#cboxClose_disabled').attr('id', 'cboxClose'); },
    onComplete: function(){ $('#cboxLoadedContent').append('first opened') },
    html:'<p>First <a id="second-btn" href="x">second</a></p>',
    width: 500, height: 200
  });
}

$('#first-btn').live('click', function(e){
  e.preventDefault();
  showfirst()
});

showfirst();

Hey, am I talking alone?! XD

小糖芽 2024-12-21 07:03:09

这就是我要使用的;对此不满意:
- 我强迫一个广泛使用的插件执行一个简单的任务(关闭一个窗口并打开另一个窗口)
- 它需要覆盖每个shadowbox功能(现在仅实现播放器“html”)。

这里有一个完整的工作示例

var shadowbox_orig_open = Shadowbox.open;
Shadowbox.reOpenable = function(new_opts) {
    if(Shadowbox.isOpen()){
        // close other dialog
        Shadowbox.options.onClose(Shadowbox.getCurrent());

        if(new_opts.player == "html"){
            $('#sb-player').fadeOut('normal', function(){ $(this).html(new_opts.content).fadeIn(); });
        }else{
            // ???
        }

        // set other new hooks
        Shadowbox.options = new_opts.options;
    }else{
        shadowbox_orig_open(new_opts);
    }
};

Here's what I'll use; not happy with this as:
- I'm forcing a widely used plugin doing a simple task (close a window and open another)
- it needs to override each shadowbox feature (now only player "html" is implemented).

Here a full working example.

var shadowbox_orig_open = Shadowbox.open;
Shadowbox.reOpenable = function(new_opts) {
    if(Shadowbox.isOpen()){
        // close other dialog
        Shadowbox.options.onClose(Shadowbox.getCurrent());

        if(new_opts.player == "html"){
            $('#sb-player').fadeOut('normal', function(){ $(this).html(new_opts.content).fadeIn(); });
        }else{
            // ???
        }

        // set other new hooks
        Shadowbox.options = new_opts.options;
    }else{
        shadowbox_orig_open(new_opts);
    }
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文