class TLoadComplete{ constructor( callbackFunc, frequency ){ this.callback = callbackFunc || (()=>{ console.log("completed")}); this.frequency = frequency || 500; } start(){ if (this.started) return; this.started = true; let me = this; this.images = [...document.images]; this.interval = setInterval(()=>{ let result = me.images.filter(el => !el.complete).length == 0 && document.fonts.ready; if (result) { me.callback(); console.log("completed"); me.stop(); } }, me.frequency) } stop(){ clearTimeout(this.interval); this.started = false; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter