Keyboard shortcuts

Press ← or → to navigate between chapters

Press ? to show this help

Press Esc to hide this help

mc.loadFontFace(Object object)

动态加载网络字体,文件地址需为下载类型。

注意:

  1. 字体文件返回的 contet-type 参考 font,格式不正确时会解析失败。
  2. 字体链接为http时需要启用http
  3. 字体链接必须是同源下的,或开启了cors支持,应用的域名是service.morecross.cn

Object object 参数

属性类型默认值必填说明
globalBooleanfalse否是否全局生效
familyString是定义的字体名称
sourceString是字体资源的地址。建议格式为 TTF 和 WOFF,WOFF2 在低版本的iOS上会不兼容。
descObject否可选的字体描述符
successFunction否接口调用成功的回调函数
failFunction否接口调用失败的回调函数
completeFunction否接口调用结束的回调函数(调用成功、失败都会执行)

Object.desc 的结构

属性类型默认值必填说明
styleString'normal'否字体样式,可选值为 normal / italic / oblique
weightString'normal'否字体粗细,可选值为 normal / bold / 100 / 200../ 900
variantString'normal'否设置小型大写字母的字体显示文本,可选值为 normal / small-caps / inherit

示例代码:

mc.loadFontFace({
  family: 'Bitstream Vera Serif Bold',
  source: 'url("https://sungd.github.io/Pacifico.ttf")',
  complete: function (res) {
    console.log(res);
  }
})