Last active
August 29, 2015 14:21
-
-
Save dima-f1/6eb6f6adde5465d7cf0d to your computer and use it in GitHub Desktop.
Отслеживаем событие загрузки кастомного шрифта с помощью FontFaceObserver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <style> | |
| @import url(http://fonts.googleapis.com/css?family=НАЗВАНИЕ_ШРИФТА&subset=cyrillic,latin); | |
| /* шрифт по умолчанию, до тех пор пока не подгружен новый шрифт */ | |
| body {font-family: sans-serif;} | |
| /* новый шрифт */ | |
| .fontOneLoad body { | |
| font-family: 'НАЗВАНИЕ_ШРИФТА', cursive; | |
| } | |
| </style> | |
| <script src='js/fontfaceobserver.js'></script> | |
| <script> | |
| // инициализация | |
| var fontOneLoad = new FontFaceObserver('НАЗВАНИЕ_ШРИФТА', {}); | |
| fontOneLoad | |
| .check() | |
| .then(function () { // событие, когда шрифт загружен | |
| // добавляем класс тегу html | |
| document.documentElement.className += " fontOneLoad"; | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment