keen-slider icon indicating copy to clipboard operation
keen-slider copied to clipboard

slideChanged event firing several times when looping is enabled

Open nick-elpedes opened this issue 2 years ago • 3 comments

I had an issue where slideChanged would fire more than once when changing from my last slide to my first slide.

Besides enabling looping, all settings when initializing the slider are default. I added a hook into sliderChange to show what I am trying to describe.

// printing animator to show index of slide being pushed
slider.on("slideChanged", () => {
            console.log(slider.animator);
          });

Screenshot 2022-12-14 at 3 39 08 PM

In the screenshot above, I have a slider looping through 3 slides. When it switches from slide 3 to slide 1, it fires the slideChanged event 3 times instead of 1 time.

nick-elpedes avatar Dec 14 '22 20:12 nick-elpedes

Hey @nick-elpedes

this behavior is correct. Here is an example how you could achieve what you want: https://codesandbox.io/s/relaxed-torvalds-bltizs?file=/src/App.js

rcbyr avatar Dec 16 '22 19:12 rcbyr

Hey @nick-elpedes

this behavior is correct. Here is an example how you could achieve what you want: https://codesandbox.io/s/relaxed-torvalds-bltizs?file=/src/App.js

The code you linked still does not fire the event in a reliable way. Sometimes the event fires, sometimes it doesn't fire at all. I linked a video showing what I mean.

https://user-images.githubusercontent.com/107874690/208490229-1db98656-3a4a-43ee-8850-c9db67868d08.mp4

nick-elpedes avatar Dec 19 '22 18:12 nick-elpedes