0

I've searched similar topics on SO but none of the solutions worked for me. I'm populating my page with links via Ajax. Like so:

$.post('php/common/auction_view/auction_invoices.php', function(data){
   $('#auction-invoices').html(data);
   //Initiate Fancybox on links
   $("a.example4").fancybox({
            'opacity'       : false,
            'overlayShow'   : false,
            'transitionIn'  : 'elastic',
            'transitionOut' : 'elastic',
            'type'          : 'iframe'
   });
});

Although, this doesn't work. Does anyone have a solution? Thanx!

EDIT: Okey, found the solution:

$.post('php/common/auction_view/auction_invoices.php', function(data){
$('#auction-invoices').html(data);
$.getScript("fancybox/jquery.fancybox-1.3.4.js", function(){
    $.fancybox.init();
    $("a.example4").fancybox({
        'transitionIn'      : 'elastic',
        'transitionOut'     : 'elastic',
        'overlayShow'       : false, 
        'showCloseButton'   : true, 
        'width'             : 450, 
        'height'            : 585, 
        'titleShow'         : false, 
        'type'              : 'iframe'
    });
});

});

enter code here
Ismailp
  • 2,333
  • 4
  • 37
  • 66

2 Answers2

0

This answer did not help me, it's to complicated, but this is solution that helped me (jquery 1.7.2 and fancybox 1.3.4):

Open jquery.fancybox-1.3.4.js and edit it about line 790 like this

    $.fn.fancybox = function(options) {
    if (!$(this).length) {
        return this;
    }

    $(this)

        .unbind('click.fb')
        .live('click.fb', function(e) {
         $(this).data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {})))
            e.preventDefault();

This solution solved my problems, and there is no need to change anything else, even initialisation remain like default.

$(".trigger").fancybox();

It's simple and clean. Hope that helps.

Miljan Puzović
  • 5,840
  • 1
  • 24
  • 30
0

Fancybox v1.3.x doesn't support dynamically added elements.

I answered a similar question here, which uses the jQuery .on() method to bind fancybox to dynamically added elements.

Tweak the code to match your container like:

$("#auction-invoices").on("focusin", function(){...
Community
  • 1
  • 1
JFK
  • 40,963
  • 31
  • 133
  • 306