草案
此页面不完整。

这是 实验性技术
检查 浏览器兼容性表格 要小心谨慎在生产中使用这之前。

FontFace() 构造函数创建新 FontFace 对象。

句法

var fontFace = new FontFace(family, source, descriptors);
					

参数

系列
Specifies a name that will be used as the font face value for font properties. Takes the same type of values as the font-family descriptor of @font-face .
source
The font source. This can be either:
  • A URL
  • Binary font data
descriptors 可选
A set of optional descriptors passed as an object. It can have the following keys:
  • 系列 : Family
  • style : Style
  • weight : Weight
  • stretch : Stretch
  • unicodeRange : Unicode range
  • variant : variant
  • featureSettings : Feature settings

范例

async function loadFonts() {
    const font = new FontFace('myfont', 'url(myfont.woff)');
    // wait for font to be loaded
    await font.load();
    // add font to document
    document.fonts.add(font);
    // enable font with CSS class
    document.body.classList.add('fonts-loaded');
}
					

规范

规范 状态 注释
CSS Font Loading Module Level 3
The definition of 'FontFace Constructor' in that specification.
工作草案 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
FontFace() 构造函数 Chrome 35 Edge 79 Firefox 41 IE ? Opera 22 Safari 10 WebView Android 37 Chrome Android 35 Firefox Android 41 Opera Android 22 Safari iOS 10 Samsung Internet Android 4.0

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

另请参阅

元数据

  • 最后修改: