A CSS-only Carousel
I've recently read about and discussed CSS Scroll Snapping so often that I felt like I should build a CSS-only carousel based on it. There it is:
Here are a few things to note: #
Accessibility is in line with all other CSS-only experiments: it can only be considered mediocre in term of semantics and visual indicators. Don't do this in production.
The going forward and back is done via a combination of CSS Scroll Snap together with scroll-behavior: smooth
and moving the focus through the slides via anchor links.
The nicest trick I pull off is the one for the auto-forward:
- first I slowly offset the scroll snap points to the right, making the scroll area follow along due to being snapped to them.
- after having scrolled the width of a whole slide, I deactivate the snapping. The scroll area is now untied from the scroll snap points.
- Now I let the scroll snap points jump back to their initial positions without them "snap-dragging" the scroll area back with them
- Then I re-engage the snapping which now lets the scroll area snap to a different snap point 🤯 Whatever... look at the code 🙃
The cover image of this post is Carousel spinning in Sunset by bubutu
Webmentions
+10
-
-
-
-
-
-
-
Nolan Lawson has written about a similar experiment: nolanlawson.com/2019/02/10/bui…. Something I noticed in your implementation when playing with it on iOS is that the whole page scrolls up when I swipe/scroll the carousel.
-
-
-
-
-
-
-
-