This slider is built with vanilla JavaScript (no jQuery and no plugins). Instead of calling a library function, we wrote the slider logic ourselves in
javascript-slider.js.
.viewport is the “window” that shows the images..track is a long strip that holds every slide side-by-side..slide is exactly 100% of the viewport width..viewport uses overflow: hidden so off-screen slides don’t show..track uses display:flex to line slides up horizontally.transition:transform ... creates the smooth sliding animation.object-fit:
cover; crops image to fill the windowcontain; shows the entire image (may letterbox).The JavaScript keeps track of one main value: the current slide index (0, 1, 2, 3). When the index changes, we:
transform: translateX(...).active class
In javascript-slider.css, adjust the height on .slide img.
/* TRY THIS: change slider height */
.slide img {
height: 350px; /* try 250px, 400px, 500px */
}
/* cover = fills frame (crops) | contain = shows whole image (letterbox) */
.slide img {
object-fit: cover; /* try contain */
}
The speed is controlled by CSS (not JavaScript) because we’re animating the transform.
/* TRY THIS: faster/slower slide animation */
.track {
transition: transform 0.35s ease; /* try 0.2s or 0.6s */
}
.nav styles for arrow size, color, and background..dot and .dot.active styles for the indicators..track, .dot, etc.).<head>, it must use defer (like this page does).