Hi,
I’m new to javascript and lazy loading, after much googling and fumbling around I came up with this:
[code]
let imgTag = “<img class=”pos” src=””
let lazyTag = “” loading=”lazy” alt=”…” />”
let imgPath = “imgs\aquarelle\main\”
fetch(“paintings.json”)
.then(response => response.json())
.then(data => {
for(let i = 0; i < data.aquarelle.length; i++){
document.querySelector(“#debug”).innerHTML
+= imgTag
+ imgPath + JSON.stringify(data.aquarelle[i].imgMain).replace(/[‘”]+/g, ”)
+ lazyTag + “<br>”
}
})
to generate a lazy load image gallery from a JSON file
Wanted to know if using this code gives me the advantage of lazy loading, or if someone can suggest a better way to do this.
Thanks