activate lightbox on dynamically added content

前端 未结 2 1113
死守一世寂寞
死守一世寂寞 2020-12-21 11:08

I\'m developing a little portfolio where I can choose a category and when I click it, the content (thumbnails) of that category will be shown (this is via an array).

相关标签:
2条回答
  • 2020-12-21 11:54

    You can call many jQuery lightboxes with $.lightboxName(), e.g.

    $('a[rel=lightbox]').live('click', function(e){
      e.preventDefault;
      $.fancybox({ href : $(this).attr('href') });
      // OR $.colorbox({ href : $(this).attr('href') });
    });
    

    Note that jQuery now recommends using .on() instead of .live().

    0 讨论(0)
  • 2020-12-21 12:03

    If you are binding the links with a regular event handler:

    $('a[rel=lightbox]').click(function(e){ ... });
    

    Then any new content that is added after the bind won't be captured.

    You can either rerun the bind when you change out the content, or more simply use jQuery's event delegation to attach the handler:

    $('a[rel=lightbox]').live('click', function(e){ ... });
    
    0 讨论(0)
提交回复
热议问题