I am implementing a Infinte Scroll Carousel with Lit. I want to control the carousel with key events. On long key press (or throttled) I want the animation te be fluid and stop at a specific place.
Is it possible to animate the items in virtalizer with some CSS and avoid using window.scrollTo API?
I tried to use virtualizer.element(n).scrollIntoView but did not get the desired result
I will assume you used
scrollIntoView()with thebehavior: 'smooth'option from the README:Because Virtualizer works by directly manipulating the absolute positions of its light-DOM child elements aka rendered items, its use of computed styles or observances by the ResizeObserver, which are how it identifies moments to recalibrate due to possible visibility changes, may conflict with some animation approaches if they were applied directly to children in CSS.
However, if you are able to apply your CSS animation/transitions to the containing element, i.e. the
<lit-virtualizer>custom element itself or the containing element of thevirtualize()directive if that was used, you may be able to create the effect you want.In this video I am doing a very broad overview of Virtualizer, but at the specific time in the link 5:24 I am trying to show visually that Virtualizer is basically just a big container that pretends to hold all the children and if you can control the position of that container in the viewport then CSS animations transitions for that container element should function as expected.
https://www.youtube.com/watch?v=ay8ImAgO9ik&t=324s
If
scroller: truethen it is trickier as a separate container element is used inside.If you have more details you can share about your use case, I'd be interested in reviewing it further as an issue at https://github.com/lit/lit/issues