我对jQuery非常了解,但是我需要解决这个问题:我有一个基于Drupal的网页,并且创建了一个在Colorbox中打开的地图(借助于Colorbox Node模块)。因此,页面上有一个超链接:<a class="colorbox-node init-colorbox-node-processed-processed" href="/places_fullscreen">Open in fullscreen</a>
。<div>
用#colorbox
css-selector单击它将在Colorbox-overlay中可见。首先,我想在打开颜色框时捕获事件,然后执行一些操作。
我浏览了Internet寻求解决方案,并试图实施它们,但没有成功。
第一条建议:
(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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句