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

[VanillaJS][v5] translate3d values for slides are sometimes wrong #413

Open
BOLT04 opened this issue Mar 20, 2024 · 0 comments
Open

[VanillaJS][v5] translate3d values for slides are sometimes wrong #413

BOLT04 opened this issue Mar 20, 2024 · 0 comments

Comments

@BOLT04
Copy link

BOLT04 commented Mar 20, 2024

Hello,

I'm using keen-slider v5 and I'm having issues with the slide positions when clicking the arrows to navigate slides. The slider I'm using has dots and arrows and this issue only happens sometimes. Usually when we navigate the page, the slider is rendered and immediately after we click one of the arrows, but the entire page or slider instance hasn't fully loaded.

From what I investigated, the value for the x axis used in the function slidesSetPositions sometimes has the wrong value. But it's not always the same value for a given slide. While debugging, only this variable would change:

const absoluteDistance = trackSlidePositions[idx].distance * width

If this distance changed then sometimes my slides would have the wrong position, meaning they get "half-cut".
example of slides with wrong position:
image

example of slides with correct position:
image

It seems to only happen after the first click on one of the arrows, if we go back to these slides after clicking the arrow, they show up in the correct position.

This is my code snippet with the keen-slider options:

const keenSliderConfig = {
      loop: true,
      controls: true,
      rubberband: false,
      centered: true,
      mode: "free-snap",
      slidesPerView: 2,
      spacing: 10,
      breakpoints: {
          "(min-width: 1280px)": {
              controls: false,
              centered: false,
              slidesPerView: 5,
              spacing: 10,
          },
      },
      created: (instance) => {
          const relativeSlide = instance.details().relativeSlide;
          const absoluteSlide = instance.details().absoluteSlide;
          sliderWrapper.querySelector(".arrow--left").addEventListener("click", (e) => {
                  instance.refresh();
                  instance.moveToSlide(absoluteSlide - 5);
              });
               sliderWrapper.querySelector(".arrow--right").addEventListener("click", (e) => {
                  instance.refresh();
                  instance.moveToSlide(absoluteSlide + 5);
              });
          });
      },
      slideChanged(instance) {
          // update dots and classes
      },
};

new KeenSlider(".slider", keenSliderConfig);

I'm using moveToSlide for the arrows but using instance.prev and next I get the same problem.
Can someone help me figure out why the x position is wrong or what other problem could cause this issue?

Any help is appreciated.
Thanks!

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

1 participant