Preloading @font-face fonts?

前端 未结 13 1883
时光说笑
时光说笑 2020-12-04 11:13

Is it possible to preload or otherwise cache @font-face fonts, most likely with javascript, before the page loads so you don\'t get that ugly jump when the page finally does

13条回答
  •  悲哀的现实
    2020-12-04 11:54

    Via Google's webfontloader

    var fontDownloadCount = 0;
    WebFont.load({
        custom: {
            families: ['fontfamily1', 'fontfamily2']
        },
        fontinactive: function() {
            fontDownloadCount++;
            if (fontDownloadCount == 2) {
                // all fonts have been loaded and now you can do what you want
            }
        }
    });
    

提交回复
热议问题