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

Bug?: Slidechanged event is delayed, when using dot-values in slidesPerView #49

Closed
stefanbayjensen opened this issue Aug 21, 2020 · 2 comments

Comments

@stefanbayjensen
Copy link

I don't know if this is a bug, or a feature request
I've noticed, that the slideChanged event, is slightly delayed, when using a dot-value in slidesPerView – I've been able yo replicate it, with the following example:

import "./styles.css";
import "keen-slider/keen-slider.min.css";
import KeenSlider from "keen-slider";

const slider = new KeenSlider("#my-keen-slider", {
  slidesPerView: 2.5,
  slideChanged: (instance) => {
    console.log("slideChanged");
  }
});

const next = document.querySelector("[data-next]");

next.addEventListener("click", () => slider.next());
@rcbyr
Copy link
Owner

rcbyr commented Aug 21, 2020

Hello @stefanbayjensen

it is not a bug but maybe a missing feature. Currently no internal slide index is set by calling next() or moveToSlide(idx). Instead, a distance is defined that must be moved to get to this index. During movement, the slider checks which slide is closest to the origin point. What is in your case, the left side of the viewport. I hope this is understandable.

Currently, the only way to get the index immediately is to modify the index outside the slider and use moveToSlide instead of next.

But I add a feature for this, in the next big update. (in a couple of weeks/months)

@rcbyr
Copy link
Owner

rcbyr commented Dec 3, 2021

I have added this function in the new major version. At each next, moveToIdx or dragEnd the animationStarted event is fired. At this time the targetIdx of the animation is set and can be used as the next active index. You can find an implementation here: https://keen-slider.io/examples#thumbnails

@rcbyr rcbyr closed this as completed Dec 3, 2021
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

2 participants