admin管理员组

文章数量:1200396

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

I'm using this code:

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

If there anything wrong with this code?

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

I'm using this code:

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

If there anything wrong with this code?

Share Improve this question edited Jan 4, 2012 at 14:27 Rory McCrossan 338k41 gold badges319 silver badges350 bronze badges asked Jan 4, 2012 at 14:25 Satch3000Satch3000 49.4k89 gold badges224 silver badges349 bronze badges 2
  • Is the missing brace and bracket at the end just a mistake when you copied and pasted? – Rory McCrossan Commented Jan 4, 2012 at 14:28
  • If that's all of your code you're missing some closures at the end "})". A little more code and a link would be handy – Alex Commented Jan 4, 2012 at 14:28
Add a comment  | 

3 Answers 3

Reset to default 18

Description

Assuming your using jack moore's colorbox jQuery plugin you have to change onClose to onClosed and use open:true. And you always have to close the function.

Check out the jsFiddle Demonstration.

Sample

Html

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

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

  • jsFiddle Demonstration
  • jack moore's colorbox jQuery plugin

Update

'onClose' should be 'onClosed'

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

I recommend use the event handlers that come with 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.

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

本文标签: javascriptColorBox Onclose function not workingStack Overflow