我正在尝试使用名为 ColorBox (http://colorpowered.com/colorbox/) 的 Jquery Lightbox,但遇到了一些麻烦。
我想使用灯箱来显示内联内容,但也会出现下一个和上一个按钮。这样,就像在照片库中一样,我可以浏览所有与下一个和上一个按钮共享相同 id 属性的项目。如果我将它硬编码到模板中,它可以工作,但如果我像粘贴在帖子末尾那样自动化它,它就不会。
我经常添加一个新元素,所以在开头添加一个新元素需要的时间比我想要的要长。所以我自动化了这个过程,生成的代码看起来和你的一模一样(在你的帖子中),但是颜色框不起作用。有人现在如何修复它(如果可能的话)?帮助将不胜感激。
这有效:
<p><a class="group1" href="#box1">Grouped Photo 1</a></p>
<p><a class="group1" href="#box2">Grouped Photo 2</a></p>
<p><a class="group1" href="#box3">Grouped Photo 3</a></p>
<div id="box1">
Some text in box 1 Some text in box 1
Some text in box 1
Some text in box 1
Some text in box 1
Some text in box 1
</div>
<div id="box2">
Some text in box 2
Some text in box 2
Some text in box 2
Some text in box 2
Some text in box 2
</div>
<div id="box3">
Some text in box 3
Some text in box 3
Some text in box 3
Some text in box 3
Some text in box 3
</div>
如果我像这样编辑上面的代码,它不会
<div class="links">
<p><a class="group1">Grouped Photo 1</a></p>
<p><a class="group1">Grouped Photo 2</a></p>
<p><a class="group1">Grouped Photo 3</a></p>
</div>
<div class="boxes">
<div>
Some text in box 1 Some text in box 1
Some text in box 1
Some text in box 1
Some text in box 1
Some text in box 1
</div>
<div>
Some text in box 2
Some text in box 2
Some text in box 2
Some text in box 2
Some text in box 2
</div>
<div>
Some text in box 3
Some text in box 3
Some text in box 3
Some text in box 3
Some text in box 3
</div>
</div>
和 javascript:
$('.links a').each(function(index) {
$(this).attr("href","#box"+index);
});
$('.boxes div').each(function(index) {
$(this).attr("id","#box"+index);
});
$(".group1").colorbox({rel:'group1', inline:true, href:$(this).attr('href'), width:"60%"});
这会遍历所有链接并将它们添加到与链接在 href 属性中具有相同的 id