lightbox in page loaded with ajax

2

Hello, I'm trying to create a new page in php but I do not know anything at all. I just used java that I removed from an example to dynamically load pages and to do one lightbox ... the problem is when I want to conjugate the 2 .... I want the lightbox to work inside a page loaded with ajax .... here is the code:

page index.php

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script><scripttype="text/javascript">
  $(document).ready(function(){
    $("#menu a").click(function( e ){
      e.preventDefault();
      var href = $( this ).attr('href');
      $("#center_content").load( href +" #center_content");
    });
  });
</script>

and in the "center_content" div the contents are loaded .... now on the content page with lightbox

<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script><scripttype="text/javascript" src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script><scripttype="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/fancybox/1.3.4/jquery.fancybox-1.3.4.pack.min.js"></script><scripttype="text/javascript">
  $(function($){
    var addToAll = false;
    var gallery = false;
    var titlePosition = 'over';
    $(addToAll ? 'img' : 'img.fancybox').each(function(){
      var $this = $(this);
      var title = $this.attr('title');
      var src = $this.attr('data-big') || $this.attr('src');
      var a = $('<a href="#" class="fancybox"></a>').attr('href', src).attr('title', title);
      $this.wrap(a);
    });
    if (gallery)
      $('a.fancybox').attr('rel', 'fancyboxgallery');
    $('a.fancybox').fancybox({
      titlePosition: titlePosition
    });
  });
  $.noConflict();
</script>

NOTE: I can not put the script's calls but they are the .... Can someone tell me what to modify? because of this I do not understand NOTHING!

    
asked by anonymous 15.12.2015 / 01:45

1 answer

4

You can only instantiate a lightbox after its html exists.

$("#center_content").load( href +" #center_content", function() {
    //aqui dentro você dispara o lightbox
});

link

Dude, in addition, you should not bring any javascript on the loaded page.

Leave it all available on the first load and do not bring any script tags via ajax.

    
15.12.2015 / 13:56