Reputation: 67
I've seen questions regarding this issue on here already, but I'm having a different issue trying to get it to work.
With the following code I want to add a classname to the colorbox lightbox once it has opened.
For some reason though the second function (where .addclass is executed) does not work (when I inspect the code in firebug it doesn't even enter that function).
$(document).ready(function(){
$(".box1").colorbox(function(){
$("#colorbox").addClass("box1");
});
});
Is it something I'm missing or am I trying to do this incorrectly?
Thanks Ian
Upvotes: 2
Views: 8124
Reputation: 13649
UPDATE:
Newer versions of Colorbox support the new className setting which can be used to add extra class names to colorbox.
Original answer:
You need to specify the onOpen callback for colorbox like this:
$(document).ready(function(){
$(".box1").colorbox({onOpen: function(){
$("#colorbox").addClass("box1");
}});
});
There's also an option to listen for the cbox_open
event instead of using a callback - see http://jacklmoore.com/colorbox/ for more information.
Upvotes: 10
Reputation: 161
This will do the trick, it's a new attribute:
$('.my-box').colorbox({className: 'my-class'});
Upvotes: 3
Reputation: 868
Try this, as per the EventHook section on ColorBox.
$(document).bind('cbox_complete', function(){
$("#colorbox").addClass("box1");
});
Upvotes: 3