1window.addEventListener("load", function () { 2 // lazy loads elements with the below selector 3 const observer = lozad('.lazy-raster-cs', { 4 load: function (el) { 5 el.classList.add('lazy-fade-cs') 6 if (el.hasAttribute("data-srcset")) { 7 if (el.hasAttribute("data-sizes")) { 8 el.sizes = el.dataset.sizes; 9 } 10 el.srcset = el.dataset.srcset; 11 } 12 if (el.hasAttribute("data-src")) { 13 el.src = el.dataset.src; 14 } 15 }, 16 loaded: function (el) { 17 // Custom implementation on a loaded element 18 el.classList.add('loaded-cs'); 19 // Masonry (Not really needed because the placeholder has the good aspect ratio) 20 // but who knows 21 if(window.Masonry) { 22 document.querySelectorAll('.masonry').forEach(element=>{ 23 let masonry = Masonry.data(element); 24 masonry.layout(); 25 }) 26 } 27 } 28 }); 29 observer.observe(); 30}); 31 32