1
votes

I have an issue triggering afterClose fancybox 2.1.4 event.

I have an init script like this

$.fancybox({
  maxWidth    : 900,
  maxHeight   : 600,
  fitToView   : false,
  width       : '70%',
  height      : '70%',
  autoSize    : false,
  closeClick  : false,
  openEffect  : 'none',
  closeEffect : 'none',
  afterClose  : function() {
    alert('Hi!');
    return;
  }
});

I have a DIV that triggers a function that fills a DIV with HTML data

<div onclick="projectDetail('+project.id+')">View Details</div>

The trigger function that fills in the fancybox content DIV is this

function proyectDetail(id) {
  var project = $('#project');

  var result = '<h2>Lorem ipsum dolor sit amet</h2>\
                 <p>\
                   Lorem ipsum dolor sit amet, consectetur adipiscing elit.\
                 </p>';
  project.append(result);

  $.fancybox(project);
}

The issue is that the afterClose event doesn't gets fired!

I need just to click that div, open fancybox and clear contents after fancybox close, because, the popup may be filled with different data, depending on given project id.

Thanks in advise!

1
If you mean, opening and closing project in fancybox, of course it will never trigger afterClose because you haven't set any. - JFK

1 Answers

1
votes

afterClose doesn't get fired because you haven't set any. You open fancybox this way

$.fancybox(project);

... but in order to trigger afterClose, you have to set it as an API option within that function like

$.fancybox(project, {
    afterClose: function () {
        alert("you have closed fancybox");
    }
});

See JSFIDDLE