如何使用 jQuery 捕捉彩盒打开事件?
How to catch the colorbox opening event using jQuery?
我对 jQuery 有非常非常基础的了解,但我需要解决这个问题:我有一个基于 Drupal 的网页,我创建了一个在 Colorbox 中打开的地图(借助于Colorbox Node 模块)。所以页面上有一个超链接:<a class="colorbox-node init-colorbox-node-processed-processed" href="/places_fullscreen">Open in fullscreen</a>
。单击它,<div>
和 #colorbox
css-选择器将在 Colorbox-overlay 中可见。
首先,我想在颜色框打开时捕捉事件,然后做一些事情。
我在互联网上浏览了解决方案并尝试实施它们但没有成功。
第一个建议:
(function($) {
$(".colorbox-node").colorbox( {
onComplete: function() {
console.log('ColorBox is currently open');
}
});
})
第二条建议:
(function($) {
if ($("#colorbox").css("display")=="block") {
console.log('ColorBox is currently open');
}
})
正确的解决方案是什么?
好吧,我了解到我应该使用 Drupal 行为。所以下面的代码可以解决问题:
(function ($) {
Drupal.behaviors.whateverName= {
attach: function (context, settings) {
if ($('#colorbox').css('display') == 'block') {
console.log('ColorBox is currently open');
}
}
};
}) (jQuery);
我对 jQuery 有非常非常基础的了解,但我需要解决这个问题:我有一个基于 Drupal 的网页,我创建了一个在 Colorbox 中打开的地图(借助于Colorbox Node 模块)。所以页面上有一个超链接:<a class="colorbox-node init-colorbox-node-processed-processed" href="/places_fullscreen">Open in fullscreen</a>
。单击它,<div>
和 #colorbox
css-选择器将在 Colorbox-overlay 中可见。
首先,我想在颜色框打开时捕捉事件,然后做一些事情。
我在互联网上浏览了解决方案并尝试实施它们但没有成功。
第一个建议:
(function($) {
$(".colorbox-node").colorbox( {
onComplete: function() {
console.log('ColorBox is currently open');
}
});
})
第二条建议:
(function($) {
if ($("#colorbox").css("display")=="block") {
console.log('ColorBox is currently open');
}
})
正确的解决方案是什么?
好吧,我了解到我应该使用 Drupal 行为。所以下面的代码可以解决问题:
(function ($) {
Drupal.behaviors.whateverName= {
attach: function (context, settings) {
if ($('#colorbox').css('display') == 'block') {
console.log('ColorBox is currently open');
}
}
};
}) (jQuery);