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

[Nuxt 3/ Vue 3] Change animation duration and easing type for swiping #436

Open
michaelprys opened this issue Aug 22, 2024 · 0 comments
Open

Comments

@michaelprys
Copy link

michaelprys commented Aug 22, 2024

I posted this issue on nuxt-keen-slider github page modbender/nuxt-keen-slider#1, but I think it also makes sense to post it here, since it's related to the carousel options.

Reproduction: https://stackblitz.com/edit/nuxt-starter-wuvuih?file=app.vue

Issue:
In the documentation in says 'defaultAnimation sets the default animation of the functions moveToIdx, next and prev'. However, it looks like it sets the animation only for next and prev and not moveToIdx.

Is there any way to change the duration and the type of the animation (like easing: "cubic-bezier(0.25, 0.1, 0.25, 1)") when swiping?

I managed to change the duration, but it only works when clicking on the navigation buttons, and not when swiping.

const current = ref(0);
const [container, slider] = useKeenSlider({
  slides: {
    perView: 1,
    spacing: 15,
  },
  initial: current.value,
  slideChanged: (s) => {
    current.value = s.track.details.rel;
  },
  defaultAnimation: {
    duration: 1300, // works only for navigation buttons and when clicking on gallery thumbnails, but not when swiping
  },
});

I tried changing dragSpeed, but looks like it works for a different purpose.
Here I modify the duration according to the docs. Also tried adding it to 'animationStarted'. Doesn't work:

function addClickEvents() {
  slider.slides.forEach((slide, idx) => {
    slide.addEventListener("click", () => {
      main.value.moveToIdx(idx, undefined, { duration: 1300 }); 
    });
  });
}
slider.on("created", () => {
  addActive(slider.track.details.rel);
  addClickEvents();
  main.value.on("animationStarted", () => {
    slider.animator.options.duration = 1300; // Also tried accessing the duration this way. Doesn't work.
    removeActive();
    const next = main.value.animator.targetIdx || 0;
    addActive(main.value.track.absToRel(next));
    slider.moveToIdx(Math.min(slider.track.details.maxIdx, next));
  });
});

If we take a look at the keen-slider source code and go to line 436 - (here's the Codepen by simulant144: https://codepen.io/simulant144/pen/WNqJvqz), there was a duration set to 500ms by default. If we change it to n.options.duration and now go to the line 825 and change this duration to let's say 5000ms it starts to work. Hope it helps to fix the issue. There should be an option just like in defaultAnimation: { duration }, but for swiping as well.

Looking for a possible solution.

@michaelprys michaelprys changed the title Change animation duration and easing type for swiping [Nuxt 3/ Vue 3]Change animation duration and easing type for swiping Aug 22, 2024
@michaelprys michaelprys changed the title [Nuxt 3/ Vue 3]Change animation duration and easing type for swiping [Nuxt 3/ Vue 3] Change animation duration and easing type for swiping Aug 22, 2024
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