Swipe icon indicating copy to clipboard operation
Swipe copied to clipboard

Special case if two slides error

Open ghost opened this issue 11 years ago • 5 comments

Hi, I have a problem with the special case with exactly two slides. In the swipe.js file is a handling for this case:

//special case if two slides
if (browser.transitions && options.continuous && slides.length < 3) {
  element.appendChild(slides[0].cloneNode(true));
  element.appendChild(element.children[1].cloneNode(true));
  slides = element.children;
}

In this case the two elements are copied to four. The data-index are incremented from 1 to 4 and the rest included id's are copied, so there are two pairs of divs with the same id. This causes errors in the prev and next values, so the swipe runs in the range 1 to 4 and not 1 to 2.

I have deleted these lines and now it works as expected.

For me it's a bug. Please explain.

ghost avatar Mar 25 '14 14:03 ghost

+1 on this. Removing those lines fixes the doubling issue. However, deleting them introduces new prolems: The slider now shows an "erratic" behaviour and is no longer capable of sliding smoothly between the two elements + the only transition now is sliding from right to left with a blank background before sliding starts.

I guess the slide-clones are supposed to act as doubles to provide a smooth transition between the two slides creating an illusion that it is only two slides, when it in fact is four. Nonetheless, it would be great if this could be solved without cloning somehow. When you are using embed codes in the sliders the issue sometimes gets worse.

aaslun avatar Feb 04 '15 09:02 aaslun

Since sliders containing two slides introduces this special scenario where the slides are cloned, here's a proposed workaround for when the slider.getPos() returns index of cloned slides (which may be misleading), i.e. if slider.getPos() is returning higher integer values than the number of slides available in the slider (due to the clones that are counted):

var slider = $('.slider').data('slider');
var currentIndex = slider.getPos() + 1;
currentIndex = currentIndex > slider.getNumSlides() ? currentIndex - slider.getNumSlides() : currentIndex;
alert('You are viewing slide ' + currentIndex + ' of ' + slider.getNumSlides());

Then use currentIndex instead to avoid situations where you get a index that is 3 of 2 or 4 of 2 slides.

aaslun avatar Feb 04 '15 10:02 aaslun

@rmoszczynski @aaslun Hi guys , I maintain a independent Swipe project https://github.com/lyfeyaj/swipe (originally fork from this project) with bugfixes, features and new versions, and this bug has been fixed in https://github.com/lyfeyaj/swipe, you can take a look at it. ^_^ Hoping it is helpful to you.

lyfeyaj avatar Mar 02 '15 03:03 lyfeyaj

@aaslun Hi i implemented as per you mentioned. but still i was facing the issue. i.e if slider is working fine then touch swipe is giving problem.

sureshbuzz avatar Apr 20 '16 14:04 sureshbuzz

I came upon this issue when fixing a bug at work. As you can see, it clones both sliders messing up the counter. What we did was:

index++;
var nextSlide = index > totalImages ? Math.floor(index / totalImages) : index;

Where:

  • totalImages are all of my slides (2 in this case);
  • index is my current slide (it goes from 0 to 3)

I hope it helps somebody out there. Peace

dpw1 avatar Apr 18 '17 11:04 dpw1