Colorbox :针对多个灯箱以不同方式绑定 cbox_complete
我正在使用“COLORBOX”(http://colorpowered.com/colorbox/)。
我的页面上有两个不同的颜色框,它们的访问方式如下。
$("#link_1").live('click', function() {
$.fn.colorbox({width:"1100px", height:"645px", inline:true, href:"#box_1"});
return false;
});
$("#link_2").live('click', function() {
$.fn.colorbox({width:"1100px", height:"645px", inline:true, href:"#box_2"});
return false;
});
对于每个颜色框,我需要通过绑定“cbox_complete”函数进行一些“后处理”。
$('#link_1').bind('cbox_complete', function() {
// something for link_1
console.log('this happens after link_1 colorbox is opened!);
});
$('#link_2').bind('cbox_complete', function() {
// something for link_2
console.log('this happens after link_2 colorbox is opened!);
});
但以上两个“绑定”没有触发。如果我遵循,效果很好。
$(document).bind('cbox_complete', function() {
// something for link_1
console.log('this happens after link_1 AND link_2 colorbox is opened!);
});
如何创建两个不同的“cbox_complete”绑定?我已经尝试过
$('#link_1').live('cbox_complete', function() {.....
但这也没有任何运气。
I'm using "COLORBOX" (http://colorpowered.com/colorbox/).
I have two different colorboxes on the page and they are accessed as follows.
$("#link_1").live('click', function() {
$.fn.colorbox({width:"1100px", height:"645px", inline:true, href:"#box_1"});
return false;
});
$("#link_2").live('click', function() {
$.fn.colorbox({width:"1100px", height:"645px", inline:true, href:"#box_2"});
return false;
});
For each of the colorboxes, I need to do some "post processing" by binding "cbox_complete" function.
$('#link_1').bind('cbox_complete', function() {
// something for link_1
console.log('this happens after link_1 colorbox is opened!);
});
$('#link_2').bind('cbox_complete', function() {
// something for link_2
console.log('this happens after link_2 colorbox is opened!);
});
But above two "bindings" are not firing. If I do following, it works fine.
$(document).bind('cbox_complete', function() {
// something for link_1
console.log('this happens after link_1 AND link_2 colorbox is opened!);
});
How can I create two different "cbox_complete" bindings? I've tried
$('#link_1').live('cbox_complete', function() {.....
But this didn't have any luck either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 onComplete 回调来进行链接特定的回调。
Use the onComplete callback for link specific callbacks.
看起来这些事件仅在全局范围内触发: https:// github.com/jackmoore/colorbox/blob/master/colorbox/jquery.colorbox.js#L164
如果你这样做怎么样?
Looks like the events are only triggered globally: https://github.com/jackmoore/colorbox/blob/master/colorbox/jquery.colorbox.js#L164
How about if you do this instead?