Closed arnvvd closed 1 year ago
Latest commit: |
f35a16f
|
Status: | ✅ Deploy successful! |
Preview URL: | https://caf75e10.locomotive-boilerplate.pages.dev |
Branch Preview URL: | https://feature-fonts-check.locomotive-boilerplate.pages.dev |
Superseded by #129
Add the function
fontFacesWatcher
to watch font faces used in our website and trigger a global custom eventfontsLoaded
when all font faces are loaded. This function returns a promise that can be used to execute a script when the fonts are loaded (E.g. add a class on the body; lock/unlock the website loader...). It's a watcher not a loader, the loading process is made by the browser.To use the function correctly you need to :
<link rel="preload" href="assets/fonts/SourceSansPro-Regular.woff2" as="font" type="font/woff2" crossorigin>
.scss
into the$font-faces
array:$font-faces: ("Webfont" "SourceSansPro-Regular" 400 normal );
⚠️ As you can see, I used in my script the font alias
Webfont
not the real name of the font (SourceSansPro-Regular). The reason is that thedocument.fonts.check()
method uses the font name given in the CSS.The function
fontFacesWatcher
trigger a global custom eventfontsLoaded
. So you can use it in your modules; it's very useful for a scrolling update or a split text, for example. The function also updates the font loaded status on the window object aswindow.isFontsLoaded
, useful with Ajax and the init method of our modules. You can find the implementation inExample.js
.