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を追加します