Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carousel - Error while sliding when there is only 1 item present #250

Closed
Vuurvlieg opened this issue Oct 28, 2018 · 6 comments
Closed

Carousel - Error while sliding when there is only 1 item present #250

Vuurvlieg opened this issue Oct 28, 2018 · 6 comments

Comments

@Vuurvlieg
Copy link

Hi, its me again. There is a little problem with the v4 Carousel. It may happen that there is only 1 item in the Carousel present. If this is the case and you click the "next" button or the interval is not zero, the Carousel throws an error and the Carousel will be messed up.

The solution is simple, just move the order of the following code into this order:

  // find the right next index 
  if ( next < 0 ) { next = total - 1; } 
  else if ( next >= total ){ next = 0; }

  // first return if we're on the same item #227
  if ( activeItem === next ) {
    return;
  // or determine slideDirection
  } else if  ( (activeItem < next ) || (activeItem === 0 && next === total -1 ) ) {
    slideDirection = self[direction] = left; // next
  } else if  ( (activeItem > next) || (activeItem === total - 1 && next === 0 ) ) {
    slideDirection = self[direction] = right; // prev
  }

Please check this example and click the next button and see what will happen. Please let me know if its not clear.

@midzer
Copy link
Contributor

midzer commented Oct 28, 2018

I can reproduce the bug in your demo, @Vuurvlieg (missing slide)
There is no error thrown for me in console though

@Vuurvlieg
Copy link
Author

@midzer Thanks for taking a look. When you enter a random value for the interval, like 5000, then open the dev. console an wait a few seconds. You will see an error "Uncaught TypeError: Cannot read property 'classList' of undefined".

@thednp
Copy link
Owner

thednp commented Oct 29, 2018

Why didn't this come like 3 days ago before we launched 2.0.24?

@Vuurvlieg
Copy link
Author

I just saw yesterday that a new version was available so I downloaded this new version and tested my website. Then I ran into this issue.

thednp added a commit that referenced this issue Oct 29, 2018
* Fixing #250, V3/V4 the Carousel component will invalidate instances when only ONE `carousel-item` is found
* V3/V4 demo updates (Carousel transition timing issue)
thednp added a commit that referenced this issue Oct 29, 2018
* Fixing #250, V3/V4 the Carousel component will invalidate instances when only ONE `carousel-item` is found
* V3/V4 demo updates (Carousel transition timing issue)
@thednp thednp closed this as completed Oct 29, 2018
@Vuurvlieg
Copy link
Author

Vuurvlieg commented Oct 29, 2018

@thednp Awesome, thanks for fixing and releasing a new version!
Btw, would be better to hide the arrow indicators .carousel-control-prev & .carousel-control-next when there is only 1 slide?

@thednp
Copy link
Owner

thednp commented Oct 30, 2018

@Vuurvlieg I think that is something for you to handle via PHP or whatever environment you're in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants