Hello!
I am working on a photo gallery module and I haven’t been able to get it to work. I am very new to coding, so I am struggling to figure out what is wrong.
The video I am using as a guide is fairly old:
https://www.youtube.com/watch?v=gEV_JPlLXhs
But i thought I replicated it very well except in the JS area. The code is not working - the images are opening in a different browser instead of doing a light box effect like in the video.
Below is my code:
HTML:
<!--654671552-->
<div class=“gallery”>
{% set gallery = hubdb_table_rows(‘654671552’) %}
{% for img in gallery %}
<a class=“gallery_image” href=“{{ resize_image_url(img.image.url, 1200, 0, 0) }}” title=“{{ img.description }}”>
<img src=“{{ resize_image_url(img.image.url, 550, 0, 0) }}” alt=“{{ img.description }}” >
</a>
{% endfor %}
</div>
CSS:
.gallery {
columns: 3;
padding: 2rem;
width: 100%;
}
.gallery_image {
display: block;
max-width: 100%;
margin-bottom: 1em;
}
.gallery_image img {
max-width: 100%;
display: block;
}
.gallery_overlay {
position: fixed;
top: 0;
width: 100%;
height: 100%;
background: rgba (0,0,0,.9);
z-index: 1000000;
}
.gallery_overlay close {
position: absolute;
top: 2em;
right: 2em;
background: transparent;
color: #fff;
font-size: 1.5em;
}
.gallery_image wrapper {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100%;
max-width: 1200px;
}
.gallery_image wrapper img {
max-width: 1200px;
}
JS:
$(‘.gallery_image’).on(‘click’, function(e){
e.preventDefault();
console.log();
var url = $(this).attr(‘href’),
title = $(this).attr(‘title’);
$(‘body’).append(‘div class"gallery_overlay"><button class=“close”>close</button><div class=“gallery_image–wrapper”><img src="’ + url + ‘" alt=“”’ + title + ‘"><p>’ + title + ‘</p></div></div>’);
})-->
function closePopup(){
$(‘.gallery_overlay’).hide(‘400’, function();{
$(this).remove();
});
};
$(body).on(‘click’, ‘.close’, function(e){
closePopup();
});
Thanks in advance for any help!