kolkov / ngx-gallery

A simple responsive native gallery component for Angular 8+.
https://ngx-gallery.kolkov.ru/
MIT License
115 stars 56 forks source link

Bug - Image scrolling background when a thumbnail is clicked skipping exactly one image (only previous) #4

Closed brunoambr closed 4 years ago

brunoambr commented 4 years ago

When a thumbnail is selected and another one is chosen (skipping exactly one previous image), the middle image (that was supposed to be "skipped") appears sliding (transitioning) in background.

This bug can be seen here: https://kolkov-ngx-gallery.stackblitz.io/

When we select the last image (the bird) and then choose the clouds image, the third image appears scrolling from left to right.

I am using Angular 9 (9.0.0-rc.7) and ngx-gallery v.1.0.9.

Issue #218 from the older repo states a similar problem! (https://github.com/lukasz-galka/ngx-gallery/issues/218), so I'm recreating it here!

kolkov commented 4 years ago

Thanks for reporting this issue.

Simbaclaws commented 4 years ago

This issue is caused by the following:

Whenever the last picture is selected, only the previous left image exists in the dom with a position of left -100%. Since it is left of the birds image (the city).

Whenever a person would click on the clouds image this would mean the clouds image now exists inside the dom with left: 0 and the image that was left of the birds (the city) is now on the right of the clouds image so it would be left: 100%.

Which means since it has a transition it would animate the left property of the city from -100% to 100%. This is the reason why the image passes by.

To fix this issue you could do the following:

Now for fading, this can be done in the same way. By first adding the images to the dom without transition and afterwards simultaniously fade out the image that is to be removed from the dom and fading in the image that it is supposed to fade to.

As soon as I find the time I'll try creating some exemplary code.

And while we're at it we could also replace left: -100% to transform:translateX(-100%). Like i've explained in this issue: https://github.com/kolkov/ngx-gallery/issues/22