I'm trying to make this jquery plugin => http://leandrovieira.com/projects/jquery/lightbox/ work with multiple galleries on the same page.
The problem is, everytime I click on a picture from a certain gallery, I get all the pictures from all the galleries on the same page. Let's say i've got 2 galleries of 6 photos each. If I click on a pic from gallery 1, I will see the pics from gallery 2 as well.
I've tried something like this to make it work but no success:
<script type="text/javascript">
$(function(){
$('div.gallery-6').each(function() {
$(this).find('a.lightbox').lightBox();
});
});
</script>
Unfortunately, it doesn't work!!!
What's the workaround for that?
Once again, what I'm trying to accomplish is to be able to view the pictures in their proper gallery. I don't want all the pics to be treated as one gallery.
Can't say I've worked with this particular plugin before, but usually you add a
rel=lightbox[foo]
to the link element. Foo will be unique for each gallery on the page.Hope this gets you started on the right path; otherwise there are dozens of other lightbox plugins you can use.
Here's how I made the basic jquery lightbox linked in the original question behave with multiple galleries. No hacks, or anything. Works flawlessly.
I gave every lightbox a seperate name:
Then my HTML looks like this:
And voila, I have 2 separate galleries.
With very few changes I made this work with multiple galleries on one page.
The JQuery
The HTML
I changed the style from an id to a class.
Perhaps lightbox has changed since other answers were given, but I thought the answers on this page were good, but then I discovered that I could simply do:
That assumes an HTML structure of:
The wrapper class isn't needed, I think, but my code included it for other reasons.
You can also do it without JavaScript at all with the data-attributes.
It works also if the images are mixed up in the page.
Alternately, you could do something like this to automatically wire up any lightbox[insert gallery name here] links, like the standard lightbox.js functionality: