Bonjour gcyrillus,
Encore merci pour le suivi.
gcyrillus a écrit :
Quelle action attends tu au clic sur l'image ?
Le clic sur l'image doit si possible :
1) rester sur l'image
2) provoquer l'ouverture du carrousel en pop-up, de façon à pouvoir l'agrandir pleine page (mieux qu'une loupe selon moi).
Actuellement, si la grande image n'est pas l'image principale (img.picture)
Clic sur l'image : l'image principale s'affiche
Clic sur l'image principale : le pop-up s'ouvre.
Voilà à quoi peut ressembler le html :
<figure>
<img tabindex="0" src="im/pr/2128G.jpg" alt="" width="78" height="75" loading="lazy" />
<img class="picture" src="im/pr/2128G.jpg" id="2128X645Xjpg" alt="Mon super produit" />
<img tabindex="0" src="im/mu/2128-1G.webp" alt="" width="100" height="75" loading="lazy" decoding="async" />
<img src="im/mu/2128-1G.webp" id="2128X645Xwebp" alt="" width="280" height="210" loading="lazy" decoding="async" />
<img tabindex="0" src="im/mu/2128-2G.webp" alt="" width="100" height="75" loading="lazy" decoding="async" />
<img src="im/mu/2128-2G.webp" id="2128X645Xwebp" alt="" width="280" height="210" loading="lazy" decoding="async" />
<img tabindex="0" src="im/mu/2128-3G.webp" alt="" width="100" height="75" loading="lazy" decoding="async" />
<img src="im/mu/2128-3G.webp" id="2128X645Xwebp" alt="" width="280" height="210" loading="lazy" decoding="async" />
</figure>
J'ai le code javascript qui fonctionne bien pour l'image principale.
Dans mon esprit il devrait aussi bien fonctionner pour les autres image sauf que non, c'est le comportement expliqué plus haut en deux clics : image principale puis pop-up.
const trouve_ca_id = document.querySelector('img.picture');
const idImg = trouve_ca_id.id.split ('X');
const ca_id = idImg[0];
const imaxes = document.querySelectorAll('img.picture, img[src^="im/mu/' + ca_id + '-"] + img');
imaxes.forEach(imax => {
const tist = imax.alt;
const idImg = imax.id.split('X');
if (idImg.length < 3) {return;}
const ca_id = idImg[0];
const height = idImg[1];
const img_format = idImg[2];
imax.addEventListener('click', function() {PopGrand(ca_id, tist, height, img_format);});
});
function PopGrand (ca_id, tist, height, img_format)
{
if (!mobile.matches) {return false;}
else
{
const win = window.open ('popup.php?nom='+ encodeURI (ca_id+'G.'+img_format+'&tit='+tist), '', 'popup=yes,scrollbars=yes,resizable=yes,width=420,height='+height);
}
}
J'espère que c'est clair.
Modifié par boteha_2 (21 Jul 2025 - 19:04)