1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-10-10 01:35:14 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

字体加载逻辑优化

This commit is contained in:
2022-03-15 22:33:48 +08:00
parent bda3e3e071
commit 80a5b59bdf
5 changed files with 50 additions and 17 deletions

View File

@@ -30,23 +30,36 @@
axios.post('../fontmin/getfont', { text: text, font: "" })
.then(function (response) {
// 当接口成功返回时动态设置css
let styleDom = document.createElement('style');
styleDom.type = 'text/css';
const cssText = `
@font-face {
font-family: bookshelfplusFont;
src: url("${response.data.url}") format("truetype");
}
`
styleDom.appendChild(document.createTextNode(cssText));
document.getElementsByTagName('head')[0].appendChild(styleDom)
console.log("字体加载成功");
loadFont(response.data.url);
$("html,body").css("transition", ".05s");
setTimeout(()=>{
$("html,body").css("opacity", "1");
}, 100)
})
.catch(function (error) {
console.log("字体加载失败", error);
$("html,body").css("transition", ".05s");
setTimeout(()=>{
$("html,body").css("opacity", "1");
}, 100)
});
}
function loadFont(fontUrl) {
let styleDom = document.createElement('style');
styleDom.type = 'text/css';
const cssText = `
@font-face {
font-family: bookshelfplusFont;
src: url("${fontUrl}") format("truetype");
}
`
styleDom.appendChild(document.createTextNode(cssText));
document.getElementsByTagName('head')[0].appendChild(styleDom)
console.log("字体加载成功");
}
$(document).ready(function () {
var allText = getPageText();
// console.log(allText);