javascript - 使用 WebFont 加载器时,如何硬编码 css?

标签 javascript css google-webfonts

要使用 WebFont 加载字体,我按照他们在此处的建议进行操作:https://developers.google.com/fonts/docs/webfont_loader

WebFontConfig = {
    custom: { families: ['font1', 'font2', 'font3'],
    urls: [ 'stylesheets/fonts.css' ] },
    loading: function(){
        console.log('loaded');
    },
    inactive: function(){
        console.log('not loaded');
    }
};
WebFont.load(WebFontConfig);

但这意味着浏览器在开始加载字体之前等待 css 文件的下载。css 只是几行代码,我不明白为什么我不能直接将它粘贴到 js 中。

有人知道如何实现吗?

最佳答案

这是不可能的; css 下载完成后开始检测。

关于javascript - 使用 WebFont 加载器时,如何硬编码 css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16375554/

相关文章:

javascript - v-on :change event is not fired when javascript is used to increase value is Vue

javascript - XMLHttpRequest 可以有参数吗?

css - Google Fonts 示例页面和单独页面中的用法之间的 Barlow 渲染差异

html - 为什么 "position: relative"只在 Chrome 中有效?

html - 当动画停止播放时,DIV 一直返回到相同的位置?

email - 电子邮件签名中的谷歌字体

javascript - 检索 JSON 值不起作用 - JavaScript/jQuery

java - firefox a href# 符号导致 setter 不被调用

javascript - 滚动条在 Mozilla 和 Safari 中不起作用

javascript - 如何使用 CSS-transition/transform through JS 在每次点击时将对象旋转 120 度