fancyapps / fancybox

jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable.
http://fancyapps.com/
7.28k stars 1.78k forks source link

Gallery going to show triple cloned images #1324

Closed SynCap closed 7 years ago

SynCap commented 7 years ago

I've got a situation where all gallery images going a triple cloned in showcase mode. In initial markup all links are unique and all "href" are unique too, but in showcase mode all images multiplicates suddenly. In thumbnail bar they also occurs in a triple number.

All links looks like that:

<a class="mix type-ec" href="img/photo/ec-02.jpg" data-myorder="0" data-fancybox="gallery-ec" data-caption="<h4>EC 02</h4>">
    <div class="col-lg-3 col-md-4 col-sm-6">
        <img src="img/photo/thumb/ec-02.jpg" alt="img" />
        <div class="figcaption">
            <h4>EC 02</h4>
            <p class="price"><span>от </span>8 795 <span>₽</span></p>
            <a href="#modalForm" data-solution="ec-02" class="arctic">заказать</a>
        </div>
    </div>
</a>

All big images are shown by its correct "href" but triple. No initialization by JS code, just data attributes.

UPD: According to number of child DIVs inside a link, cause the adding corresponding number of same images into showcase. When I've replacing DIV to SPAN - all going OK.

It's a bug? Or is a feature?

fancyapps commented 7 years ago

I guess this is due to your code structure. You are trying to create an "a" element around block level elements.

Therefore browser tries to fix your code by duplicating links and if you would use developer tools, you would see that browser renders your code like this -

<p>
    <a class="mix type-ec" href="k.jpg" data-myorder="0" data-fancybox="gallery-ec" data-caption="<h4>EC 02</h4>"></a>
</p>
<div class="col-lg-3 col-md-4 col-sm-6">
    <a class="mix type-ec" href="k.jpg" data-myorder="0" data-fancybox="gallery-ec" data-caption="<h4>EC 02</h4>">
        <img src="m.jpg" alt="img">
    </a>
    <div class="figcaption">
        <a class="mix type-ec" href="k.jpg" data-myorder="0" data-fancybox="gallery-ec" data-caption="<h4>EC 02</h4>">
            <h4>EC 02</h4>
            <p class="price"><span>от </span>8 795 <span>₽</span></p>
        </a>
        <a href="#modalForm" data-solution="ec-02" class="arctic">заказать</a>
    </div>
</div>

In the end, fancyBox sees 3 links having the same data attributes.

This is how your code would work correctly - http://codepen.io/fancyapps/pen/XMPbXP?editors=1000

asaage commented 6 years ago

In the end, fancyBox sees 3 links having the same data attributes.

Could you add a check and reduce for unique items? I use fancybox in combination with a slider-plugin (owl.carousel or slick.carousel) which constanly clone my fancybox-items.

fancyapps commented 6 years ago

@asaage Simply initialise with correct selector, for example (for slick carousel):

$().fancybox({
  selector : '.slick-slide:not(.slick-cloned)',
  hash     : false
});

Demo - https://codepen.io/fancyapps/pen/pdbrjx

ghost commented 6 years ago

@fancyapps Your demo doesn't work for all cases:

@asaage For slick carousel try something like this as an alternative: https://codepen.io/anon/pen/RYWbVY

We use the slick 'init' event to

fancyapps commented 6 years ago

Hmm, what a bummber... Yes, @f4w-pwharton, you are right, clicking cloned items would display all items :/

Your demo inspired me to create a more complete solution - https://codepen.io/fancyapps/pen/jvbEgo?editors=1010 - the idea is that clicking clones would trigger click event on corresponding original item. Although, this will work only with the upcoming (v3.4) version (should be released tomorrow).

sermalefico commented 4 years ago

Could you help me to get this working with the Swiper JS library. I have the same problem with duplicate slides and can't find a way to make it work.

fancyapps commented 4 years ago

It would be similarly to this - https://fancyapps.com/fancybox/3/docs/#faq-6 But, to overcome this issue properly, this project will be split into 3 parts, see Combine & Customize section here https://fancyapps.com/next/