javascript ColorBox Onclose 功能不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8728419/
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-10-26 04:23:23  来源:igfitidea点击:

ColorBox Onclose function not working

javascriptjquerycolorbox

提问by Satch3000

I am trying to open a new colorbox window when one is closed.

我试图在关闭时打开一个新的 colorbox 窗口。

I'm using this code:

我正在使用此代码:

$(".inline").colorbox({
    inline: true, 
    width: "50%", 
    escKey: false,
    onClose: function() {
        $('#newWindow').show();
    }

If there anything wrong with this code?

如果这段代码有什么问题?

回答by dknaack

Description

描述

Assuming your using Hyman moore's colorbox jQuery pluginyou have to change onCloseto onClosedand use open:true. And you always have to close the function.

假设您使用Hyman moore 的 colorbox jQuery 插件,您必须更改onCloseonClosed并使用open:true. 而且您总是必须关闭该功能。

Check out the jsFiddle Demonstration.

查看jsFiddle 演示

Sample

样本

Html

html

<div class="firstColorBox">first</div>
<div class="secondColorBox">second</div>

jQuery

jQuery

$(".firstColorBox").colorbox({
    inline:true, 
    width:"50%", 
    escKey:false,
    onClosed:function(){
        // open the other colorBox
        $(".secondColorBox").colorbox({
                inline:true, 
                width:"50%", 
                escKey:false,
                open:true
        });     
    }
});

More Information

更多信息

Update

更新

回答by Jonathan M

'onClose' should be 'onClosed'

“onClose”应该是“onClosed”

See the reference here: http://Hymanlmoore.com/colorbox/

请参阅此处的参考:http: //Hymanlmoore.com/colorbox/

回答by user1102746

I recommend use the event handlers that come with colorbox:

我建议使用 colorbox 附带的事件处理程序:

$(document).one('cbox_closed', function () { 
    $(".secondColorBox").colorbox({...}); 
}

This will allow the javascript on the page to run. I was having issues running tags on the second popup and this solved the issue.

这将允许页面上的 javascript 运行。我在第二个弹出窗口上运行标签时遇到问题,这解决了问题。

The function one will only trigger the event once so you can close the second popup.

函数一只会触发一次事件,因此您可以关闭第二个弹出窗口。