обернуть элементы идущие подряд
De12,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.gal {
border: #0000FF 1px solid;
counter-reset: num;
}
.gal img:before {
counter-increment: num;
content: counter(num)' картинка';
}
</style>
<script>
document.addEventListener("DOMContentLoaded", function() {
const images = document.querySelectorAll('div.text img');
for (let i = 0; i < images.length; i++) {
const imgf = images[i];
const arri = [imgf];
let img = imgf.nextSibling;
while (img = img.nextSibling) {
if (img && img.nodeType === 3 && !(img.data.trim())) continue;
if (img == images[i + 1]) arri.push(images[++i]);
else break;
}
if (arri.length > 1) {
const gal = document.createElement('div')
gal.className = 'gal';
imgf.parentElement.replaceChild(gal, imgf);
gal.append(...arri)
}
}
});
</script>
</head>
<body>
<div class="col-12 text">
<img data-src="/uploads/posts/2021-11/1636154460_default-good-1.png" class="fr-fic fr-dii lazy-loaded" alt="" src="/uploads/posts/2021-11/1636154460_default-good-1.png">
<img data-src="/uploads/posts/2021-11/1636154460_default-good-1.png" class="fr-fic fr-dii lazy-loaded" alt="" src="/uploads/posts/2021-11/1636154460_default-good-1.png">
<img data-src="/uploads/posts/2021-11/1636154460_default-good-1.png" class="fr-fic fr-dii lazy-loaded" alt="" src="/uploads/posts/2021-11/1636154460_default-good-1.png"> test test
<img data-src="/uploads/posts/2021-11/1636154460_default-good-1.png" class="fr-fic fr-dii lazy-loaded" alt="" src="/uploads/posts/2021-11/1636154460_default-good-1.png">
<img data-src="/uploads/posts/2021-11/1636154460_default-good-1.png" class="fr-fic fr-dii lazy-loaded" alt="" src="/uploads/posts/2021-11/1636154460_default-good-1.png">
<b>test</b>
<img data-src="/uploads/posts/2021-11/1636154460_default-good-1.png" class="fr-fic fr-dii lazy-loaded" alt="" src="/uploads/posts/2021-11/1636154460_default-good-1.png">
<img data-src="/uploads/posts/2021-11/1636154460_default-good-1.png" class="fr-fic fr-dii lazy-loaded" alt="" src="/uploads/posts/2021-11/1636154460_default-good-1.png">
<img data-src="/uploads/posts/2021-11/1636154460_default-good-1.png" class="fr-fic fr-dii lazy-loaded" alt="" src="/uploads/posts/2021-11/1636154460_default-good-1.png">
</div>
</body>
</html>
Последний раз редактировалось рони, 06.11.2021 в 11:55.
|