mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-10-10 01:35:14 +08:00
字体加载逻辑优化
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user