Colorbox :针对多个灯箱以不同方式绑定 cbox_complete

发布于 2024-12-08 04:12:10 字数 1108 浏览 0 评论 0原文

我正在使用“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

娇俏 2024-12-15 04:12:10

使用 onComplete 回调来进行链接特定的回调。

Use the onComplete callback for link specific callbacks.

撑一把青伞 2024-12-15 04:12:10

看起来这些事件仅在全局范围内触发: https:// github.com/jackmoore/colorbox/blob/master/colorbox/jquery.colorbox.js#L164

如果你这样做怎么样?

$("#link_1").live('click', function() {
    $.fn.colorbox({
        width:"1100px", height:"645px",
        inline:true, href:"#box_1"
    }, function () {
        console.log('this happens after link_1 colorbox is opened!);
    });
});

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?

$("#link_1").live('click', function() {
    $.fn.colorbox({
        width:"1100px", height:"645px",
        inline:true, href:"#box_1"
    }, function () {
        console.log('this happens after link_1 colorbox is opened!);
    });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文