dev-resources.site
for different kinds of informations.
#LearnedToday: Slider in pure CSS
Published at
1/16/2024
Categories
webdev
css
learnedtoday
slider
Author
danielzotti
Author
11 person written this
danielzotti
open
🏞️ Do you remember when you had to use heavy JS libraries to create image slideshows?
💪 Those days are gone! You can do it in pure CSS now! (experimental in Chrome, Edge and Opera)
Main concepts
-
Scroll timeline: define a name and a direction for the scrollable element on which the shorthand CSS
scroll-timeline
property is applied. -
Animation Timeline: The
animation-timeline
CSS property specifies the timeline (defined by thescroll-timeline
property) that is used to control the progress of a CSS animation. -
Timeline scope: The
timeline-scope
CSS property modifies the scope of a named animation timeline. -
Animation range: The
animation-range
CSS shorthand property is used to set the start and end of an animation's attachment range along its timeline, i.e. where along the timeline an animation will start and end.
The idea
- Associate an horizontal (x axis) scroll timeline to the element that contains the slides (
.slider__entries
) using thescroll-timeline
property (it's a sort of event listener of the scroll event for CSS)
.slider__entries {
scroll-timeline-name: --carousel;
scroll-timeline-axis: x; // horizontal
}
- Raise the scope of the timeline from the child (
.slider__entries
) to the parent (.slider
) using thetimeline-scope
property
.slider {
timeline-scope: --carousel;
}
- Associate the scroll animation to the single "dot" in order to highlight the correct "dot"
@keyframes color-bullet {
from,
to {
background: var(--dot-color--active);
}
}
.dot a {
animation: color-bullet linear;
animation-timeline: --carousel;
animation-range: calc((var(--i) - 1) / 5 * 100%) calc(var(--i) / 5 * 100.01%); // NB: 5 is because we have 5 images in the example!
}
- Adding a "snap" effect during the scroll and hide the scrollbar
.slider__entries {
scroll-snap-type: x mandatory; // horizontal
scrollbar-width: none; // hide scrollbar
scroll-behavior: smooth; // scroll smoothly
}
- Adding the slide switch when clicking on the button
<!-- DOT: -->
<a href="#slide_01"></a>
<!-- SLIDE: -->
<a name="slide_01"><img src="..." /></a>
Demo
I created as usual a working demo.
slider Article's
30 articles in total
infinity slider
read article
Build A Stunning Animated Travel Image Slider Using Html, Css, And JavaScript!
read article
Slider in Flutter
read article
SLIDER ANIMATION HELP
read article
Making a slider puzzle in Java Script
read article
#LearnedToday: Slider in pure CSS
currently reading
Flutter - Triangular CAROUSEL Slider
read article
looking for a slider package for angular
read article
Creating a Slider using Next.js and CSS
read article
Create Dynamic Image Slider with PHP and MySQL
read article
A step-by-step guide to creating a beautiful slider with Swiper and React
read article
Animating using sliders in JavaFX and SceneBuilder
read article
Product Gallery Slider for WooCommerce
read article
What is a slider and why you should slider on your website?
read article
Kaydırıcı robot
read article
Basic JavaScript slider ready source
read article
Pure CSS Vertical Image Slider Using Only HTML & CSS
read article
How to make a simple slider component in React
read article
Responsive Image slider using Owl Carousel | HTML & CSS
read article
Simple Slider on a pure JavaScript
read article
Image Slideshow HTML CSS
read article
Ngx Slick Carousel In Angular Material Card with Custom Arrows
read article
How to make a Full Slider with javascript in 10 mins
read article
Let's build a slider from scratch in React Native
read article
Elegant & Beautiful Testimonial Sliders
read article
Choppy Slider: The Styles
read article
Flutter. A Quarter Round Slider.
read article
VueJS: Double range slider component
read article
Styling Range Sliders with CSS
read article
AWS – Using Multiple (Staging, UAT and Production) Accounts Under AWS Organization
read article
Featured ones: