Galerie photos 8
by Simon Hi
HTML
<main class="my">
<div class="my__slider"></div>
</main>
<footer><a href="https://www.jerome-turpin-peintre.net/">Jérôme Turpin</a></footer>
CSS
body {
margin: 0;
padding: 0;
background: #000;
font-family: sans-serif;
}
.my {
position: relative;
margin: 0 auto;
height: calc(100vmin - 2em);
}
.my__slider {
display: block;
background: rgb(27,39,57);
height: calc(100vmin - 2em);
}
.my__slider .aroundImg {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: flex;
}
.my__slider img {
position: relative;
z-index: 2;
display: block;
max-width: 100%;
max-height: 100%;
margin: auto;
transition: opacity 2.5s;
opacity: 0;
}
.my__slider img.frontImg {
opacity: 1;
}
footer {
display:block;
position:relative;
width: 100%;
height: 2em;
line-height: 2em;
text-align: center;
z-index:100;
}
footer a {
color: #fff;
}
JavaScript
(function() {
let securizer = 'https://www.jerome-turpin-peintre.net/';
let imxdir = 'Paints/';
let files = ['891821315.jpg', '1246581686.jpg', '1830048771.jpg', '462460138.jpg', '1789688476.JPG', '1346932134.JPG', '1531067318.JPG', '609566650.JPG', '1661767458.JPG', '64655801.jpg', '1535052137.jpg', '1421233062.jpg', '1931555642.jpg', '1934001560.jpg', '2062150141.jpg', '708741694.jpg', '1766555734.jpg', '1460277203.jpg', '1580920118.jpg', '1114744238.jpg', '433263859.jpg', '1642884494.jpg', '1511965389.jpg', '287414540.jpg', '48438334.jpg', '435098576.jpg', '2038821993.jpg', '192262232.jpg', '136420375.jpg', '733202856.jpg'];
let elem = document.querySelector('.my');
let c = elem.querySelector('.my__slider');
function addImg(src, onload) {
let div = document.createElement("div");
let img = document.createElement("img");
div.classList.add("aroundImg");
div.appendChild(img);
c.appendChild(div);
img.onload = onload;
img.src = src;
return img;
}
function slide(d) {
let ko, k, km = files.length;
let frontImg = elem.querySelector('.frontImg');
let behindImg = elem.querySelector('.behindImg');
for (k = 0; k < km; k++)
if ((securizer + imxdir + files[k]) == frontImg.src) {
ko = k;
break;
}
if (d > 0) {
if (ko < (km - 1)) ko++;
else ko = 0;
} else {
if (ko > 0) ko--;
else ko = km - 1;
}
if (behindImg) c.removeChild(behindImg.parentNode);
behindImg = frontImg;
frontImg = addImg(securizer + imxdir + files[ko],
function() {
behindImg.offsetHeight
behindImg.classList.replace("frontImg", "behindImg");
frontImg.classList.add("frontImg");
});
}
document.addEventListener('DOMContentLoaded', function() {
let frontImg = addImg(securizer + imxdir + files[0], function() {
frontImg.classList.add("frontImg");
setInterval(function() {
slide(1);
}, 5000);
});
});
})();