1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
| <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
img {
width: 200px;
height: 150px;
}
.effetfoto {
animation: efoto 0.25s;
}
#zomclic {
height: 500px;
background-repeat: no-repeat;
background-size: contain;
}
@keyframes efoto {
0% {
transform: rotate(0deg);
}
100% {
opacity: 1;
transform: rotate(360deg) scale(0, 0);
}
}
.effetfoto2 {
animation: efoto2 0.25s;
}
@keyframes efoto2 {
0% {
transform: scale(1, 0);
opacity: 0;
}
100% {
transform: scale(1, 1);
opacity: 1;
}
}
</style>
</head>
<body>
<div id="galerie">
<dl id="photo">
<dt> </dt>
<dd>
<figure
id="zomclic"
class="zoome centbvente"
data-image="http://webcom/photos/photos/9-astuce.jpg"
style="background-image: url('http://webcom/photos/photos/9-astuce.jpg')"
>
<img
id="big_pict"
name="princ_pict"
src="http://webcom/photos/photos/9-astuce.jpg"
alt="photo de Soulager les piqures de moustique"
class="effetfoto2"
/>
</figure>
</dd>
</dl>
<div id="carousel">
<div id="contentcara">
<ul id="galerie_mini"></ul>
</div>
<button id="prev">◀</button>
<button id="next" style="display: none">▶</button>
</div>
</div>
<script>
const images = [
// On crée un tableau avec les noms et infos des images
{ nomimage: '9-astuce.jpg', titre: 'Info de photo 9' },
{ nomimage: '10-astuce.jpg', titre: 'Info de photo 10' },
{ nomimage: '11-astuce.jpg', titre: 'Info de photo 11' },
{ nomimage: '13-astuce.jpg', titre: 'Info de photo 13' },
{ nomimage: '14-astuce.jpg', titre: 'Info de photo 14' },
{ nomimage: '15-astuce.jpg', titre: 'Info de photo 15' },
{ nomimage: '16-astuce.jpg', titre: 'Info de photo 16' },
{ nomimage: '18-astuce.jpg', titre: 'Info de photo 18' }
]
const photos = document.getElementById('galerie_mini'),
big_photo = document.getElementById('big_pict'),
back_photo = document.getElementById('zomclic'),
titre_photo = document.getElementsByTagName('dt')[0]
var baliseli = ''
titre_photo.innerText = images[0].titre // On affiche le titre de la première image
for (let indeximg of images) {
baliseli += `<li><img class="baliseLien" src="http://webcom/photos/${indeximg.nomimage}" title="${indeximg.titre}" alt="photo de Soulager les piqures de moustique"></li>`
}
photos.innerHTML = baliseli // On affiche les balises li dans "galerie-mini"
//On boucle pour créer un array des balises li
for (let baliseLienSelect of document.querySelectorAll('.baliseLien')) {
let backgroun = back_photo.dataset.nameimage //On récupère le nom de l'ancienne image via l'attribut "data-image"
baliseLienSelect.addEventListener('click', () => {
titre_photo.innerText = baliseLienSelect.title // Titre de l'image sélectionnée
setTimeout(() => {
back_photo.style.backgroundImage = `url("${baliseLienSelect.src}")` // l'url = au li sélectionné
big_photo.classList.remove('effetfoto2')
big_photo.classList.add('effetfoto')
big_photo.src = back_photo.dataset.image //l'image précédente affichée en haut à gauche
}, 50)
setTimeout(() => {
big_photo.classList.remove('effetfoto')
big_photo.classList.add('effetfoto2')
back_photo.style.backgroundImage = backgroun // Nom de l'ancienne image pour l'url de "background-image"
back_photo.dataset.image = baliseLienSelect.getAttribute('src') // Nom de la nouvelle image pour l'attribut "data-image"
}, 150)
})
}
</script>
</body>
</html> |
Partager