Answer the question
In order to leave comments, you need to log in
How to make a simple thumbnail gallery?
I inevitably have jquery connected with a bunch of other libraries, so I use it anyway. there is no need to additionally use a third-party heavy gallery with thumbnails, but my own version doesn’t work either (in js I understand like a dog, but I can’t say)
I have two blocks, large photos are displayed in one, thumbnails go separately in the second block.
<div class="images">
<img src="img/01.png" class="active"/>
<img src="img/02.png" />
<img src="img/03.png" />
<img src="img/04.png" />
</div>
<div class="thumbs">
<a href="img/01.png" class="show-image"><img src="img/thumb-sea.png"></a>
<a href="img/02.png" class="show-image"><img src="img/thumb-bird.png"></a>
<a href="img/03.png" class="show-image"><img src="img/thumb-galaxy.png"></a>
<a href="img/04.png" class="show-image"><img src="img/thumb-sunset.png"></a>
</div>
.images img {display: none}
.images .active {display: block}
$(".show-image").click(function() {
event.preventDefault();
var mainImage = $(this).attr("href");
$(".images img[src = mainImage]").addClass('active');
});
Answer the question
In order to leave comments, you need to log in
He doesn't like queryselector, do otherwise, here is an example like jsfiddle.net/straj/z03yk9bb/1
I'm not sure, but it should work like this:
and to remove active from the rest of the img:$(".images img").removeClass('active');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question