Attempting to create a basic carousel using scroll-snap, but encountering an issue where the carousel is randomly scrolling on load instead of starting with the first picture. See code snippet below. Any ideas on resolving this?
.carousel {
display: flex;
overflow-x: scroll;
scroll-snap-type: x mandatory;
width: 80%;
}
.carousel-img{
scroll-snap-align: start;
width: 200px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
</style>
<body>
<div class="carousel">
<img class="carousel-img" src="https://picsum.photos/300" alt="">
<img class="carousel-img" src="https://picsum.photos/301" alt="">
<img class="carousel-img" src="https://picsum.photos/302" alt="">
<img class="carousel-img" src="https://picsum.photos/303" alt="">
<img class="carousel-img" src="https://picsum.photos/304" alt="">
<img class="carousel-img" src="https://picsum.photos/305" alt="">
<img class="carousel-img" src="https://picsum.photos/306" alt="">
<img class="carousel-img" src="https://picsum.photos/307" alt="">
<img class="carousel-img" src="https://picsum.photos/308" alt="">
<img class="carousel-img" src="https://picsum.photos/309" alt="">
<img class="carousel-img" src="https://picsum.photos/310" alt="">
<img class="carousel-img" src="https://picsum.photos/311" alt="">
<img class="carousel-img" src="https://picsum.photos/312" alt="">
<img class="carousel-img" src="https://picsum.photos/313" alt="">
<img class="carousel-img" src="https://picsum.photos/314" alt="">
<img class="carousel-img" src="https://picsum.photos/315" alt="">
<img class="carousel-img" src="https://picsum.photos/316" alt="">
</div>
</body>
</html>