diff --git a/layout/includes/layout.pug b/layout/includes/layout.pug index 60ef023..73799a9 100644 --- a/layout/includes/layout.pug +++ b/layout/includes/layout.pug @@ -23,18 +23,18 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside const arr = !{JSON.stringify(bgStyleArr)} const webBgDiv = document.getElementById('web_bg') - function setRandomBg() { + const setRandomBg = () => { webBgDiv.style = arr[Math.floor(Math.random() * arr.length)] + requestAnimationFrame(() => webBgDiv.classList.add('bg-animation')) } - setRandomBg() document.addEventListener('pjax:send', () => { - setRandomBg() - // Reload CSS animation + webBgDiv.style = '' webBgDiv.classList.remove('bg-animation') - void webBgDiv.offsetWidth - webBgDiv.classList.add('bg-animation') }) + + document.addEventListener('pjax:complete', setRandomBg) + document.addEventListener('DOMContentLoaded', setRandomBg) })() !=partial('includes/sidebar', {}, {cache: true}) @@ -56,4 +56,4 @@ html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside !=partial('includes/footer', {}, {cache: true}) include ./rightside.pug - include ./additional-js.pug \ No newline at end of file + include ./additional-js.pug