$(".gallery__list").mouseover(function(){
let thumbnail = event.target.closest('#single_image');
if (!thumbnail) return;
showThumbnail(thumbnail.href, thumbnail.title);
event.preventDefault();
function showThumbnail(href, title) {
largeImg.src = href;
largeImg.alt = title;
}
});
<div class="gallery__list">
<a href="images/gallery-img-1.png" class="galleru__item galleru__item-prem" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-1.png" alt="" id="largeImg">
</a>
<a href="images/gallery-img-1.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-1.png" alt="">
</a>
<a href="images/gallery-img-2.png" class="galleru__item" id="single_image" data-fancybox="gallery" data-src="images/gallery-img-2.png">
<img src="images/gallery-img-2.png" alt="">
</a>
<a href="images/gallery-img-2.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-2.png" alt="">
</a>
<a href="images/gallery-img-1.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-1.png" alt="">
</a>
<a href="images/gallery-img-1.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-1.png" alt="">
</a>
<a href="images/gallery-img-2.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-2.png" alt="">
</a>
<a href="images/gallery-img-2.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-2.png" alt="">
</a>
<a href="images/gallery-img-1.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-1.png" alt="">
</a>
<a href="images/gallery-img-1.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-1.png" alt="">
</a>
<a href="images/gallery-img-2.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-2.png" alt="">
</a>
<a href="images/gallery-img-2.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-2.png" alt="">
</a>
</div>
<div class="gallery__list">
<a href="images/gallery-img-1.png" class="galleru__item galleru__item-prem" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-1.png" alt="" id="largeImg">
</a>
<a href="images/gallery-img-1.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-1.png" alt="">
</a>
<a href="images/gallery-img-2.png" class="galleru__item" id="single_image" data-fancybox="gallery" data-src="images/gallery-img-2.png">
<img src="images/gallery-img-2.png" alt="">
</a>
<a href="images/gallery-img-2.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-2.png" alt="">
</a>
<a href="images/gallery-img-1.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-1.png" alt="">
</a>
<a href="images/gallery-img-1.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-1.png" alt="">
</a>
<a href="images/gallery-img-2.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-2.png" alt="">
</a>
<a href="images/gallery-img-2.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-2.png" alt="">
</a>
<a href="images/gallery-img-1.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-1.png" alt="">
</a>
<a href="images/gallery-img-1.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-1.png" alt="">
</a>
<a href="images/gallery-img-2.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-2.png" alt="">
</a>
<a href="images/gallery-img-2.png" class="galleru__item" id="single_image" data-fancybox="gallery">
<img src="images/gallery-img-2.png" alt="">
</a>
</div>
function showThumbnail($img, href, title) {
$img.attr('src', href);
$img.attr('alt', title);
}
$(".gallery__list").each(function($gallery){
let $largeImg = $gallery.find('.galleru__item-prem');
$gallery.mouseover(function(event){
let thumbnail = event.target.closest('.galleru__item');
if (!thumbnail) return;
showThumbnail($largeImg, thumbnail.href, thumbnail.title);
});
});
function showThumbnail(img, href, title) {
img.src = href;
img.alt = title;
}
document.querySelectorAll('.gallery__list').forEach(function(gallery){
const largeImg = gallery.querySelector('.galleru__item-prem');
if (!largeImg) console.warn('Нет большой картинки');
gallery.addEventListener('mouseover', function(event){
const thumbnail = event.target.closest('.galleru__item');
if (!thumbnail) return;
showThumbnail(largeImg, thumbnail.href, thumbnail.title);
});
});
-let thumbnail = event.target.closest('#single_image');
+let thumbnail = $(this).find('#single_image');