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.

Revisions

  1. dima-f1 revised this gist May 25, 2015. No changes.
  2. dima-f1 created this gist May 25, 2015.
    22 changes: 22 additions & 0 deletions Custom fonts load event
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    <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>