fix: 随机背景适配 Pjax

This commit is contained in:
着火的冰块nya
2025-11-25 12:29:48 +08:00
parent c882e84cd2
commit 57a7db7a52
2 changed files with 18 additions and 6 deletions

View File

@@ -14,15 +14,27 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside
if theme.background
if !Array.isArray(theme.background)
#web_bg(style=getBgPath(theme.background))
#web_bg.bg-animation(style=getBgPath(theme.background))
else
#web_bg
#web_bg.bg-animation
- const bgStyleArr = theme.background.map(getBgPath)
script.
(function () {
(() => {
const arr = !{JSON.stringify(bgStyleArr)}
const randomBgStyle = arr[Math.floor(Math.random() * arr.length)]
document.getElementById('web_bg').style = randomBgStyle
const webBgDiv = document.getElementById('web_bg')
function setRandomBg() {
webBgDiv.style = arr[Math.floor(Math.random() * arr.length)]
}
setRandomBg()
document.addEventListener('pjax:send', () => {
setRandomBg()
// Reload CSS animation
webBgDiv.classList.remove('bg-animation')
void webBgDiv.offsetWidth
webBgDiv.classList.add('bg-animation')
})
})()
!=partial('includes/sidebar', {}, {cache: true})