2020-12-30 18:11:46 +08:00
|
|
|
KEEP.initHeaderShrink = () => {
|
2020-11-20 12:02:22 +08:00
|
|
|
KEEP.utils.headerShrink = {
|
2020-10-21 19:36:38 +08:00
|
|
|
|
|
|
|
pageTemplateDom: document.querySelector('.page-main-content'),
|
|
|
|
headerDom: document.querySelector('.header-wrapper'),
|
2021-01-04 21:16:07 +08:00
|
|
|
sidebarToolsDom: document.querySelector('.sidebar-tools'),
|
2020-10-21 19:36:38 +08:00
|
|
|
isHeaderShrink: false,
|
2020-11-25 16:54:44 +08:00
|
|
|
isShowHeaderDrawer: false,
|
2020-10-21 19:36:38 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
this.headerDom.classList.add('header-wrapper-shrink');
|
|
|
|
this.pageTemplateDom.classList.add('page-main-content-top-shrink');
|
2021-01-04 21:16:07 +08:00
|
|
|
this.sidebarToolsDom && this.sidebarToolsDom.classList.add('shrink');
|
2020-10-21 19:36:38 +08:00
|
|
|
} else if (this.isHeaderShrink && scrollTop <= this.headerHeight) {
|
|
|
|
this.isHeaderShrink = false;
|
|
|
|
this.headerDom.classList.remove('header-wrapper-shrink');
|
|
|
|
this.pageTemplateDom.classList.remove('page-main-content-top-shrink');
|
2021-01-04 21:16:07 +08:00
|
|
|
this.sidebarToolsDom && this.sidebarToolsDom.classList.remove('shrink');
|
2020-10-21 19:36:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
initMenuBarButton() {
|
2020-11-25 16:54:44 +08:00
|
|
|
document.querySelector('.menu-bar').addEventListener('click', () => {
|
|
|
|
this.isShowHeaderDrawer = !this.isShowHeaderDrawer;
|
|
|
|
document.body.style.overflow = this.isShowHeaderDrawer ? 'hidden' : 'auto';
|
2020-10-21 19:36:38 +08:00
|
|
|
this.headerDom.classList.toggle('header-drawer-show');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
initWindowMask() {
|
2020-11-25 16:54:44 +08:00
|
|
|
document.querySelector('.window-mask').addEventListener('click', () => {
|
|
|
|
this.isShowHeaderDrawer = !this.isShowHeaderDrawer;
|
|
|
|
document.body.style.overflow = this.isShowHeaderDrawer ? 'hidden' : 'auto';
|
2020-10-21 19:36:38 +08:00
|
|
|
this.headerDom.classList.toggle('header-drawer-show');
|
|
|
|
});
|
|
|
|
},
|
2020-09-11 15:06:38 +08:00
|
|
|
}
|
2020-11-20 12:02:22 +08:00
|
|
|
KEEP.utils.headerShrink.init();
|
|
|
|
KEEP.utils.headerShrink.initMenuBarButton();
|
|
|
|
KEEP.utils.headerShrink.initWindowMask();
|
2020-12-30 18:11:46 +08:00
|
|
|
}
|