优化打字机效果,添加随机文字可选设置

This commit is contained in:
roozen 2023-08-03 16:49:53 +08:00
parent 73a99f8481
commit 86cdd8fcc8
2 changed files with 49 additions and 18 deletions

View File

@ -92,6 +92,7 @@ spec:
value:
enable_above:
typed:
enable_typed_random:
enable_above_video:
index_img:
phone_index_img:
@ -115,10 +116,24 @@ spec:
children:
- $formkit: text
name: text
label: 文字
placeholder: 请输入文字
label: 自定义文字
placeholder: 请输入自定义文字
- $formkit: radio
label: 随机文字
if: $get(enable_above).value
name: enable_typed_random
key: enable_typed_random
id: enable_typed_random
value: false
help: 如果配置了自定义文字,优先展示自定文字
options:
- label: 启用
value: true
- label: 禁用
value: false
- $formkit: radio
if: $get(enable_above).value
label: 背景模式
name: enable_above_video
key: enable_above_video
id: enable_above_video

View File

@ -242,23 +242,39 @@
</style>
<script th:inline="javascript">
function subtitleType() {
fetch("https://v1.hitokoto.cn").then((t => t.json())).then((t => {
{
const e = "出自 " + t.from;
const n = [[${theme.config.top.above.typed}]].map((item) => {
return item.realNode.text;
});
n.unshift(t.hitokoto, e), window.typed = new Typed("#subtitle", {
strings: n,
startDelay: 300,
typeSpeed: 100,
loop: !0,
backSpeed: 50
})
}
}))
if([[${theme.config.top.above.enable_typed_random}]]){
fetch("https://v1.hitokoto.cn").then((t => t.json())).then((t => {
{
const e = "出自 " + t.from;
const n = [[${theme.config.top.above.typed}]].map((item) => {
return item.realNode.text;
});
n.push(t.hitokoto, e), window.typed = new Typed("#subtitle", {
strings: n,
startDelay: 300,
typeSpeed: 100,
loop: !0,
backSpeed: 50
})
}
}))
}else{
const n = [[${theme.config.top.above.typed}]].map((item) => {
return item.realNode.text;
});
window.typed = new Typed("#subtitle", {
strings: n,
startDelay: 300,
typeSpeed: 100,
loop: !0,
backSpeed: 50
})
}
}
"function" == typeof Typed ? subtitleType() : getScript("https://npm.elemecdn.com/typed.js@2.0.12/lib/typed.min.js").then(subtitleType)
// 防止加载文字太短时第一个自定义文字显示不出来
setTimeout(()=>{
"function" == typeof Typed ? subtitleType() : getScript("https://npm.elemecdn.com/typed.js@2.0.12/lib/typed.min.js").then(subtitleType)
},1800)
</script>
</th:block>
</th:block>