【问题标题】:Shadowbox - How to switch or replace content? How to close and open another dialog?Shadowbox - 如何切换或替换内容?如何关闭和打开另一个对话框?
【发布时间】:2011-12-24 09:58:03
【问题描述】:

我尝试在多个场合使用 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>

问候,
修改

【问题讨论】:

    标签: javascript jquery dialog replace shadowbox


    【解决方案1】:

    对不起,我想我会转向彩色盒,因为它看起来更稳定:

    $('#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();
    

    嘿,我一个人说话?!呵呵

    【讨论】:

    • 我遇到了和你一样的问题,或者更确切地说,我试图让一个影子框在按下内部链接后打开或刷新新内容。我接受了你的建议并搬到了 Colorbox。工作并做我想做的事。谢谢:)
    【解决方案2】:

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

    这里是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);
        }
    };
    

    【讨论】:

      猜你喜欢
      • 2012-11-10
      • 1970-01-01
      • 1970-01-01
      • 2021-04-18
      • 2023-01-31
      • 1970-01-01
      • 2015-12-30
      • 2020-11-23
      • 1970-01-01
      相关资源
      最近更新 更多