mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-10 21:17:07 +08:00
fix: 随机背景适配 Pjax
This commit is contained in:
@@ -14,15 +14,27 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside
|
|||||||
|
|
||||||
if theme.background
|
if theme.background
|
||||||
if !Array.isArray(theme.background)
|
if !Array.isArray(theme.background)
|
||||||
#web_bg(style=getBgPath(theme.background))
|
#web_bg.bg-animation(style=getBgPath(theme.background))
|
||||||
else
|
else
|
||||||
#web_bg
|
#web_bg.bg-animation
|
||||||
- const bgStyleArr = theme.background.map(getBgPath)
|
- const bgStyleArr = theme.background.map(getBgPath)
|
||||||
script.
|
script.
|
||||||
(function () {
|
(() => {
|
||||||
const arr = !{JSON.stringify(bgStyleArr)}
|
const arr = !{JSON.stringify(bgStyleArr)}
|
||||||
const randomBgStyle = arr[Math.floor(Math.random() * arr.length)]
|
const webBgDiv = document.getElementById('web_bg')
|
||||||
document.getElementById('web_bg').style = randomBgStyle
|
|
||||||
|
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})
|
!=partial('includes/sidebar', {}, {cache: true})
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ if hexo-config('enter_transitions')
|
|||||||
animation: titleScale 1s
|
animation: titleScale 1s
|
||||||
|
|
||||||
canvas:not(#ribbon-canvas),
|
canvas:not(#ribbon-canvas),
|
||||||
#web_bg
|
#web_bg.bg-animation
|
||||||
animation: to_show 4s
|
animation: to_show 4s
|
||||||
|
|
||||||
#ribbon-canvas
|
#ribbon-canvas
|
||||||
|
|||||||
Reference in New Issue
Block a user