CSS部分:
:root {
–font-family-ss: ‘’; 1.定义字体设定变量
}
@font-face {
font-family: ‘AAA’; 2.设定字体的名称和读取路径
src: url(‘/admin/AAA.ttf’) format(‘truetype’);
}
body {
font-size: 14px;
font-family: var(–font-family-ss),system-ui; 3.设定网页默认字体为定义变量
}
HTML部分:
script:
if(使用字体条件){
4. 符合条件的场合,页面使用本地AAA字体
document.documentElement.style.setProperty(‘–font-family-ss’, “AAA”);
}else{
5.其他场合,字体变量赋空,网页使用默认字体(本例为system-ui)
document.documentElement.style.setProperty(‘–font-family-style’, “”);
}