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

Manually update Carousel position #597

Closed
virgilejanssen opened this issue Dec 12, 2023 · 4 comments
Closed

Manually update Carousel position #597

virgilejanssen opened this issue Dec 12, 2023 · 4 comments

Comments

@virgilejanssen
Copy link

Is your feature request related to a problem? Please describe.

I wrote a function that changes the Carousel position on scroll. However, when I then click on an arrow or drag the carousel (with dragFree set as true), the transition starts from the last position before the scroll.

Describe the solution you'd like

How can I manually update the value saved after scrolling / Where is it stored?

Describe alternatives you've considered

No response

Additional context

No response

@fancyapps
Copy link
Owner

Hi,

Could you share your progress using any code playground?

Basically, Carousel uses Panzoom component under the hood, therefore you should interact with it.

@fancyapps
Copy link
Owner

Here is one possible solution - https://jsfiddle.net/v1tjh6ma/ (this is for a vertically aligned carousel, but should be similar to a horizontal carousel).

Sorry, custom animations or the wheel event were not considered beforehand when these components were built, therefore the solution is not that elegant.

@virgilejanssen
Copy link
Author

Yes, that's exactly what I was looking for. I didn't know Panzoom was what I needed to interact with but it opens a lot of possibilities. Thanks a lot.

@fancyapps
Copy link
Owner

If you could update to the latest, you can do the following:

myCarousel.container.addEventListener("wheel", (event) => {
  myCarousel.panzoom?.applyChange({
    panY: event.deltaY * -1,
  });

  myCarousel.setPageFromPosition()
});

https://jsfiddle.net/6ojbmsa8/

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