Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/smnh/onfontsload

Javascript utility function that notifies when requested fonts are loaded and rendered.
https://github.com/smnh/onfontsload

Last synced: about 2 months ago
JSON representation

Javascript utility function that notifies when requested fonts are loaded and rendered.

Awesome Lists containing this project

README

        

This project is not supported anymore, please refer to [FontLoader](https://github.com/smnh/FontLoader).

#onFontsLoad
Javascript utility function that notifies when specific font families are loaded and rendered. It can be useful when you want to show alternative content before specific fonts are loaded. Оr when you need to get final dimensions of non-size-fixed containers that contain font families, as dimension of these containers may change after fonts are loaded.

##Usage
First define some fonts in your page:
```html

@font-face {
font-family: DeliciousRoman;
src: url(http://www.font-face.com/fonts/delicious/Delicious-Roman.otf);
font-weight:400;
}
.myFont {
font-family: DeliciousRoman, Helvetica, Arial, sans-serif;
}

```
Then include the onFontsLoad.js
```html

```
And finally, add following function passing it array with all font-families you want to load and a callback function which will be executed once all fonts are loaded:
```javascript
onFontsLoad(["DeliciousRoman"], function(error) {
if (!error) {
// do something here, for example hide loading indicator and show elements with loaded font-families.
} else {
// error.notLoadedFontFamilies is an array of font-families that didn't loaded in specific time interval.
console.log(error.message)
}
});
```