Skip to content Skip to sidebar Skip to footer

Dynamic Links And JQuery Lightbox Issue : Loading Image In Lightbox...completely Stumped!

I have a function that dynamically creates links for a photo gallery. The function also produces a larger image as a background image of a div when and thumbnail is clicked on. Wha

Solution 1:

You can use .live() for the event handler, and .triggerHandler() to immediately open the lightbox, like this:

$("#lightboxlink").live('click', function(e){
    $(this).filter(':not(.fb)').fancybox({
        'autoDimensions' : false,
        'width' : 'auto',
        'height' : 'auto',
        'href' : fullSize
     }).addClass('fb');
     $(this).triggerHandler('click');
     e.preventDefault(); //prevent opening in new window
});

This runs .fancybox() on the link, but only if we haven't already run it, which we're tracking with a .fb class addition. Whether it's a new or fresh bind, we need to trigger the click handler, which is what fancybox listens to in order to open.


Post a Comment for "Dynamic Links And JQuery Lightbox Issue : Loading Image In Lightbox...completely Stumped!"