hexo-theme-keep/source/js/header-shrink.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

KEEP.initHeaderShrink = () => {
2020-11-20 12:02:22 +08:00
KEEP.utils.headerShrink = {
headerDom: document.querySelector('.header-wrapper'),
isHeaderShrink: false,
init() {
this.headerHeight = this.headerDom.getBoundingClientRect().height;
},
headerShrink() {
const scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
if (!this.isHeaderShrink && scrollTop > this.headerHeight) {
this.isHeaderShrink = true;
2021-01-05 11:48:58 +08:00
document.body.classList.add('header-shrink');
} else if (this.isHeaderShrink && scrollTop <= this.headerHeight) {
this.isHeaderShrink = false;
2021-01-05 11:48:58 +08:00
document.body.classList.remove('header-shrink');
}
},
initMenuBarButton() {
document.querySelector('.menu-bar').addEventListener('click', () => {
2021-01-05 11:48:58 +08:00
document.body.classList.toggle('header-drawer-show');
});
},
initWindowMask() {
document.querySelector('.window-mask').addEventListener('click', () => {
2021-01-05 11:48:58 +08:00
document.body.classList.toggle('header-drawer-show');
});
},
}
2020-11-20 12:02:22 +08:00
KEEP.utils.headerShrink.init();
KEEP.utils.headerShrink.initMenuBarButton();
KEEP.utils.headerShrink.initWindowMask();
}