Last active
December 15, 2023 09:22
-
-
Save Spike-Leung/eec9194504bb174513538ca277eaf5d4 to your computer and use it in GitHub Desktop.
Check if font has loaded
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see: https://www.zhangxinxu.com/wordpress/2022/04/js-font-face-load/ | |
// see: https://developer.mozilla.org/en-US/docs/Web/API/FontFace/FontFace | |
import fontUrl from 'fonts/SourceHanSansSC-Regular.otf' | |
function check() { | |
try { | |
const font = new FontFace('SourceHanSansSC-Regular', `url(${fontUrl})`) | |
await font.load() | |
// load success | |
} catch (e) { | |
console.error(e) | |
// load failed | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment