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

Progress unable to hit 1 with perView: 'auto' at certain viewport widths #244

Open
davidwarrington opened this issue Jun 30, 2022 · 4 comments

Comments

@davidwarrington
Copy link

Version used: 6.7.0

I've attached some arrows to my slider and I'm trying to hide them when the slider is at the beginning or the end.

Using the implementation shared at the end of #71 (but updated to reflect the newer API, and slightly modified to also support looping sliders) I'm finding that on some screen sizes the "next" arrow is never hidden.

For reference here's the arrow plugin I've written:

const useArrows = ({ next, previous } = {}) => {
  return carousel => {
    next?.addEventListener('click', carousel.next)
    previous?.addEventListener('click', carousel.prev)

    const updateButtonStates = () => {
      const { abs, min, progress } = carousel.track.details

      if (next) {
        next.disabled = progress === 1
      }

      if (previous) {
        previous.disabled = abs === min
      }
    }

    carousel.on('created', updateButtonStates)
    carousel.on('detailsChanged', updateButtonStates)
  }
}

In the example I'm currently testing with a viewport width of 1440px progress can hit 1, with a viewport width of 1415px the progress gets to 0.999 and with a viewport width the progress hits 1.000002 at a viewport width of 1414px.

I'll try to get a minimum reproducible example to share as soon as possible but wanted to share the issue I'm having now in case you have a solution in mind.

@rcbyr
Copy link
Owner

rcbyr commented Jul 7, 2022

Thank you for pointing out this problem to me. I will take care of the problem as soon as possible.

@rcbyr
Copy link
Owner

rcbyr commented Aug 8, 2022

Hey @davidwarrington

can you tell which version did you used when facing this problem. I couldn't reproduce it with the current version (v6.7.0).

@pcoeper-dd
Copy link

pcoeper-dd commented Sep 2, 2022

I think I am kind of having the same issue with v6.7.0.
I have a large container of 1492px width in which I want to display 6 slides. As I want to show a bit more than three slides per view I chose the following options:

this.slider = new KeenSlider(this.sliderRef.nativeElement, {
    initial: this.currentSlide, // = 0
    slides: { perView: () => 3.4 },
    mode: 'free-snap',
    slideChanged: (s) => {
        this.currentSlide = s.track.details.rel;
    },
});

I assume the width of each slide is not calculated correctly since I only see three slides where the third slide is already cropped on the right side. And when I try to navigate to the last slide I have no chance to display it completely. This doesn't happen for smaller screen size e.g. when you open your dev tools to the right side of your screen 😏 Let me know if you need further information!

EDIT: What I just noticed: Maybe it's a problem with the initialization? 🤔 I switched to responsive mode (with Chrome dev tolls) in order to determine the max-width where it stops working and....it looks as I would expect it. When I now switch back (leave responsive mode) everything is still fine!

@Enkil11
Copy link

Enkil11 commented Mar 30, 2024

To determine if the slider has reached its end, I utilized the following condition:
slider.track.details.maxIdx === slider.track.details.rel

I hope this proves helpful to someone, as it was precisely what I sought when I came across this thread.

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

4 participants