Javascript: Wait until fonts and images loaded
Wed Feb 07 2024 13:46:00 GMT+0000 (Coordinated Universal Time)
Saved by
@marcopinero
#javascript
const waitLoad = ( statusFunc )=>{
var imagesLoaded=false;
var fontsLoaded=false;
let interval = setInterval(()=>{
fontsLoaded = fontsLoaded || document.fonts.ready;
imagesLoaded = imagesLoaded || ([...document.images].filter(el => !el.complete).length == 0);
statusFunc( fontsLoaded && imagesLoaded );
if (fontsLoaded && imagesLoaded) clearInterval(interval);
}, 500);
}
// use waitLoad( ( state ) => console.log(state) )
content_copyCOPY
Comments