rcbyr / keen-slider

The HTML touch slider carousel with the most native feeling you will get.
https://keen-slider.io/
MIT License
4.57k stars 210 forks source link

Problem when wanting to change more than one slide at once #385

Open joaovflorisvaldo opened 8 months ago

joaovflorisvaldo commented 8 months ago

I'm developing a carousel using keen-slide, but I had problems finding a function to change more than one slide at a time. Using a for to repeatedly call the .next() function, in my case it didn't work, my solution was to set a time for it to call. Sorry for the English, I'm learning and I still use translate a little. I'll leave my code with the example timer, if you have other solutions feel free to share

const slider = new KeenSlider('#keen-Slider', { loop: false, slides: { perView: 6, spacing: 65, }, breakpoints: { "(max-width: 1024px)": { loop: true, slides: { perView: 3, spacing: 10, }, }, }, }); document.querySelector('.prev').addEventListener('click', () => { slider.prev(); setTimeout(function() { slider.prev(); }, 300); setTimeout(function() { slider.prev(); }, 600); }); document.querySelector('.next').addEventListener('click', () => { slider.next(); setTimeout(function() { slider.next(); }, 300); setTimeout(function() { slider.next(); }, 600); });