Grigory Dikiy2016-11-04 10:23:29
Grigory Dikiy, 2016-11-04 10:23:29

Ajax loading and fancybox?

Good afternoon. There are two sites on which you need to load an image gallery via ajax. At the moment, everything is done in such a way that when I click on the button, ajax image loading starts for me and, accordingly, fancybox, which is executed first, which, accordingly, cannot find the image of the same group:

/* FancyBox */
    $(document).ready(function() {
    // Gallery Photo
    $('.gallery-photo').on('click', function(event){
      var $self = $(this);

        url: "/wp-admin/admin-ajax.php",
        type: "GET",
        data: "action=get_images&id=" + $self.data('id'),
        success: function(data){
          var $gallery = $self.parent().parent().parent().find('.gallery-loop');

Well, the html itself:
<div class="item">
      <div class="img">
        <img src="<?php echo get_post_meta( get_the_ID(), 'post_poster', false )[0]['guid'] ?>" alt="">
      <div class="buttons">
        <div class="bt">
          <a class="fancyimage gallery-photo" data-id=<?php echo get_the_ID(); ?> data-fancybox-group=<?php echo get_the_ID(); ?> href="<?php echo get_post_meta( get_the_ID(), 'post_poster', false )[0]['guid']; ?>"><span><i class="fa fa-plus" aria-hidden="true"></i></span></a>
          <a href="<?php the_permalink(); ?>"><span><i class="fa fa-chevron-right" aria-hidden="true"></i></span></a>
      <div class="info">
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
      <div class="gallery-loop"></div>

Can this problem be solved?
Or are there alternatives?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Vladimir, 2016-11-04

Try calling $("a.fancyimage").fancybox();
Btw again after inserting images on the page, instead parent().parent()....parent().parent()look at.closest()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question