如何指定url来加载字体?

时间:2017-09-08 14:15:50

标签: javascript haxe webfonts

我注意到一些示例显示如何从当前网站加载字体作为加载字体的基本路径:

Browser.document.fonts.load ("1em '" + font + "'").then (function (_) {
    promise.complete (this);
});

但是我如何从特定的URL而不是网站域本身加载? 另外,1em是什么意思?

修改

< style >
("1em url('https://lab-mywebsite.com.com/files/assets/fonts') ")
</style >

1 个答案:

答案 0 :(得分:0)

如果要从网址明确预加载字体,则应直接使用js.html.FontFace构造函数:

var url = "https://fonts.gstatic.com/s/indieflower/v8/10JVD_humAd5zP2yrFqw6ugdm0LZdjqr5-oayXSOefg.woff2";

new js.html.FontFace("Indie Flower", "url($url)").load()
    .then(function (loadedFace) { /* do something with the loaded font */ });

有关工作示例,请查看此Try Haxe fiddle

据我所知,CSS字体加载模块3级草案,FontFaceSet API - 您通过document.fonts访问的API - 使您可以控制已添加到默认设置的字体的加载(例如,通过样式表/ <link>标签)。

您可以查看有关interaction with CSS font loading and matching

的更多信息