Skip to content

Instantly share code, notes, and snippets.

@dima-f1
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save dima-f1/6eb6f6adde5465d7cf0d to your computer and use it in GitHub Desktop.

Select an option

Save dima-f1/6eb6f6adde5465d7cf0d to your computer and use it in GitHub Desktop.
Отслеживаем событие загрузки кастомного шрифта с помощью FontFaceObserver
<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