我正在使用PrettyPhoto灯箱,并且我试图阻止灯箱打开,除非图像具有“活动”类。它在Contentflow脚本中使用,该脚本将活动类添加到居中的聚焦图像中。图像有一类“项目”。我正在使用 data-href ,因为由于 contentflow 中的一些限制,我需要将图像放在 a 而不是标签中。我尝试了以下代码:
HTML
<div class="item" title="Image" data-href="image.jpg" data-rel="prettyPhoto">
<img alt="image" src="thumb.jpg" /></div>
脚本
$('#gallery').on('click', '.item:not(.active)', function (e) {
e.preventDefault();
e.stopPropagation();
});
$('.item[data-href]').each(function() {
$(this).attr('href', $(this).attr('data-href'));
});
$(".item").prettyPhoto();
无论如何,每张图片都会在灯箱中打开。我也试过这个:
$('.item:not(.active)').off('click');
由于我仍在学习 jQuery,如果有人能指出我正确的方向,我将不胜感激!