Semi Auto Image Gallery
Usage
// JS (make_gallery.js):
function make_gallery(div_id, folder, images){
let html_gallery = ''
let img_folder = folder
if (folder.slice(-1) != '/'){
img_folder += '/'
}
images.forEach(img =>{
alt = img.split('.')[0]
caption = alt.charAt(0).toUpperCase() + alt.slice(1)
caption = caption.replace(/-|_/g,' ');
html_gallery += `
${caption}
`
});
document.getElementById(div_id).innerHTML = html_gallery;
document.getElementById(div_id).setAttribute('class', 'auto_gallery')
}
/* CSS (style_gallery.css): */
.auto_gallery {
padding-top: 1em;
display: flex;
flex-wrap: wrap;
justify-content: center;
background-color: #222;
gap: 15px;
}
.auto_gallery figure{
display:flex;
flex-direction:column;
width: min-content;
margin: 0;
}
.auto_gallery img{
max-height: 250px;
object-fit: contain;
max-width: 90vw;
}
.auto_gallery figcaption{
color: white;
font-family: Arial, Helvetica, sans-serif;
text-align: left;
max-width: 100vw;
padding-top: 0.5em;
padding-bottom: 1em;
}
@media screen and (max-width: 800px) {
.auto_gallery img{
max-height: 90vh;
}
}