views:

1144

answers:

3

I'm bringing in all of my images via Ajax, and I'm looking for a quick fix for the front-end of this project. I've tried a couple of jQuery lightbox plugins, but I can't seem to get them to perform in a live function (correct me if I'm wrong in thinking I need to do this).

Currently attempting to use Balupton's Lightbox Plugin (can't link because of my being a new user), and after trying all of the examples to no avail, I've attempted it with this (also not working):

$('a.lightbox-gallery').live('click', function(){
 $(this).lightbox();
});

Any help is much appreciated!

+4  A: 

1) you can hack the lightbox plugin to bind on live events 2) you can call lightbox after ajax is completed, only on new elements:

$.ajax({
    type: "POST",
    url: "url.php",
    cache: false,
    success: function(data){
     $(data).find('a[rel=lightbox]').lightbox(settings).end().appendTo('#ajaxTarget');
    }
});

For settings you can use an array to avoid writting same thing twice ;)

Ionut Staicu
+1  A: 

You can use colorbox and jquery's live function like this

$('a[rel=gallery]').live('click', function() {
  url = this.href; // this is the url of the element event is triggered from
  $.fn.colorbox({href: url});
  return false;
});
Rahul
A: 

When i do this with href it dont work.. i had to put href="#null" and use id="blabla.jpg" and use url = this.id but when i do this it just dont work properly because it dont show relation like a gallery.. it opens alone.

Tiago