参考: jsFiddle Lightbox v2.5.1 Demo
由于Lightbox脚本使用jQuery框架,因此您可以迭代所有具有 的类名称thumb
,并在该父项、锚a
链接上添加所需的必要rel="lightbox"
标记。
HTML:
<a href="http://lokeshdhakar.com/projects/lightbox2/images/examples/image-3.jpg">
<img class="thumb" src="http://lokeshdhakar.com/projects/lightbox2/images/examples/thumb-3.jpg" alt="gallery" title="Photo 1" />
</a>
<a href="http://lokeshdhakar.com/projects/lightbox2/images/examples/image-4.jpg">
<img class="thumb" src="http://lokeshdhakar.com/projects/lightbox2/images/examples/thumb-4.jpg" alt="gallery" title="Photo 2" />
</a>
<a href="http://lokeshdhakar.com/projects/lightbox2/images/examples/image-5.jpg">
<img class="thumb" src="http://lokeshdhakar.com/projects/lightbox2/images/examples/thumb-5.jpg" alt="gallery" title="Photo 3" />
</a>
jQuery:
$(document).ready(function() {
// Scan the webpage for all class names of 'thumb' that is seen.
$('.thumb').each(function(){
// For each class name of 'thumb' found, go to the parent item of that thumb and apply the rel attribute.
$(this).parent().attr('rel','lightbox[myGallery]');
});
});
由于上面使用的 jQuery 是基于您的HTML 网页布局,因此可能需要根据该页面上的实际内容进行调整。该.each();
方法也可以对其他类名重复。