Util.js 743 Bytes
Newer Older
limingzhe's avatar
limingzhe committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34




export async function loadFonts (fontName, fontFile) {


  // const font = new FontFace(
  //   "DroidSansFallback",
  //   "url(" + "../../assets/play/font/DroidSansFallback.ttf" + ")"
  // );
  
  try {
    console.log(location.href.split("#")[0] + "assets/play/font/" + fontFile);
    const font = new FontFace(
      fontName,
      "url(" + location.href.split("#")[0] + "../../assets/play/font/" + fontFile + ")"
    );
    
    console.log('start: ', new Date().getTime())
    await font.load();
    console.log('end: ', new Date().getTime())
    document.fonts.add(font);
    document.body.classList.add("fonts-loaded");

  } catch (error) {
    console.log(error);
  }
  
}


// --------------- custom class --------------------