Monday, December 26, 2022
HomeProgrammingDetecting Fonts Prepared

Detecting Fonts Prepared


Realizing when sources are loaded is a key a part of constructing useful, elegant web sites. We’re used to utilizing the DOMContentLoaded occasion (generally known as “domready”) however do you know there’s an occasion that tells you when all fonts have loaded? Let’s learn to use doc.fonts!

The doc.fonts object contains a prepared property which is a Promise representing if fonts have been loaded:

// Await all fonts being loaded
await doc.fonts.prepared;

// Now do one thing!  Possibly add a category to the physique
doc.physique.classList.add('fonts-loaded');

Font information will be comparatively giant so you possibly can by no means assume they’ve loaded rapidly. One merely await from doc.fonts.prepared offers you the reply!


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments