I recently created a horizontal scrolling image gallery with thumbnails underneath. The goal is to click on a thumbnail and have the corresponding image scroll into view.
Here's the HTML setup:
<div class="images_container">
<img id="image_1" src="/image1.jpg">
<img id="image_2" src="/image2.jpg">
<img id="image_3" src="/image3.jpg">
</div>
<div class="images_container thumbnails">
<a href="#image_1"><img src="/image1.jpg" class="thumbnail"></a>
<a href="#image_2"><img src="/image2.jpg" class="thumbnail"></a>
<a href="#image_3"><img src="/image3.jpg" class="thumbnail"></a>
</div>
And here's the CSS used:
.images_container {
overflow-x: scroll;
overflow-y: hidden;
max-height: 50rem;
white-space: nowrap;
}
.images_container.thumbnails {
max-height: 10rem;
}
.images_container img {
vertical-align: top;
height: 50rem;
}
.images_container.thumbnails img {
height: 10rem;
}
While this setup functions well, there is an issue with jumping to the correct image when clicking on a thumbnail. Sometimes, if the image is slightly within the visible viewport, it won't jump directly to it. This can be frustrating for users trying to navigate quickly.
To solve this problem, I am looking into using JavaScript to smoothly scroll the entire image into view upon clicking its thumbnail. Since jQuery isn't available for this project, I'll need to rely solely on JavaScript to implement this feature.