call jQuery function after fonts are loaded.

前端 未结 3 1097
一生所求
一生所求 2021-01-02 12:35

I have multiple fonts in web site It loads very slowly,I have some jquery functionality I need to load them when the fonts are loaded.

I have tried to call it in

3条回答
  •  执念已碎
    2021-01-02 12:58

    In order to capture the event, you'll need to use a font loader. Sadly, there isn't a cross-browser way of loading the fonts, so I suggest you try the Google WebFont Loader:

    var WebFontConfig = {
      monotype: {  // Fonts.com 
        projectId: 'YourProjectId'
      },
      active: function() {
        // do something
      }
    };
    
    (function() {
      var wf = document.createElement('script');
      wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
          '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
      wf.type = 'text/javascript';
      wf.async = 'true';
      var s = document.getElementsByTagName('script')[0];
      s.parentNode.insertBefore(wf, s);
    })();
    

提交回复
热议问题