Skip to content

Commit

Permalink
🐞 fix: 手动添加监听,弥补 reloadOnContextChange 不生效 #9
Browse files Browse the repository at this point in the history
  • Loading branch information
白云苍狗 committed Sep 19, 2022
1 parent 5050939 commit 4d85e67
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion package/hexo-theme-async/source/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,26 @@
const back_fun = function (params) {
scroll.scrollTo(0);
}

backtop.addEventListener('click', back_fun)

const desktop = window.matchMedia('screen and (min-width: 768px)');
const mobile = window.matchMedia('screen and (max-width: 767px)');

const reload = function (e) {
if (e.matches) {
location.reload();
}
}

desktop.addListener(reload);
mobile.addListener(freload);

document.addEventListener('swup:contentReplaced', (event) => {
backtop.removeEventListener('click', back_fun)
window.removeEventListener('resize', update)
ro.unobserve(container)
desktop.removeListener(reload);
mobile.removeListener(freload);
scroll.destroy()
});
},
Expand Down

0 comments on commit 4d85e67

Please sign in to comment.