2022-09-29 15:24:19 +08:00
|
|
|
/* global KEEP */
|
|
|
|
|
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
|
|
|
headerDom: document.querySelector('.header-wrapper'),
|
|
|
|
isHeaderShrink: false,
|
|
|
|
|
|
|
|
init() {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.headerHeight = this.headerDom.getBoundingClientRect().height
|
2020-10-21 19:36:38 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
headerShrink() {
|
2022-09-30 11:40:30 +08:00
|
|
|
const scrollTop = document.body.scrollTop || document.documentElement.scrollTop
|
|
|
|
const headerWrapperDom = document.querySelector('.header-wrapper')
|
|
|
|
const { enable, header_transparent } = KEEP.theme_config.style.first_screen
|
2020-10-21 19:36:38 +08:00
|
|
|
if (!this.isHeaderShrink && scrollTop > this.headerHeight) {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.isHeaderShrink = true
|
|
|
|
document.body.classList.add('header-shrink')
|
2022-09-27 17:52:45 +08:00
|
|
|
if (enable === true && header_transparent === true) {
|
2022-09-30 11:40:30 +08:00
|
|
|
headerWrapperDom.classList.add('transparent-2')
|
2022-09-27 17:52:45 +08:00
|
|
|
}
|
2020-10-21 19:36:38 +08:00
|
|
|
} else if (this.isHeaderShrink && scrollTop <= this.headerHeight) {
|
2022-09-30 11:40:30 +08:00
|
|
|
this.isHeaderShrink = false
|
|
|
|
document.body.classList.remove('header-shrink')
|
2022-09-27 17:52:45 +08:00
|
|
|
if (enable === true && header_transparent === true) {
|
2022-09-30 11:40:30 +08:00
|
|
|
headerWrapperDom.classList.remove('transparent-2')
|
2022-09-27 17:52:45 +08:00
|
|
|
}
|
2020-10-21 19:36:38 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-01-05 15:39:21 +08:00
|
|
|
toggleHeaderDrawerShow() {
|
2022-09-30 11:40:30 +08:00
|
|
|
const domList = [document.querySelector('.window-mask'), document.querySelector('.menu-bar')]
|
2020-10-21 19:36:38 +08:00
|
|
|
|
2021-01-05 15:39:21 +08:00
|
|
|
if (KEEP.theme_config.pjax.enable === true) {
|
2022-09-30 11:40:30 +08:00
|
|
|
domList.push(
|
|
|
|
...document.querySelectorAll('.header-drawer .drawer-menu-list .drawer-menu-item')
|
|
|
|
)
|
2021-01-05 15:39:21 +08:00
|
|
|
}
|
|
|
|
|
2022-09-30 11:40:30 +08:00
|
|
|
domList.forEach((v) => {
|
2021-01-05 15:39:21 +08:00
|
|
|
v.addEventListener('click', () => {
|
2022-09-30 11:40:30 +08:00
|
|
|
document.body.classList.toggle('header-drawer-show')
|
|
|
|
})
|
|
|
|
})
|
2021-01-05 15:39:21 +08:00
|
|
|
}
|
2020-09-11 15:06:38 +08:00
|
|
|
}
|
2022-09-30 11:40:30 +08:00
|
|
|
KEEP.utils.headerShrink.init()
|
|
|
|
KEEP.utils.headerShrink.headerShrink()
|
|
|
|
KEEP.utils.headerShrink.toggleHeaderDrawerShow()
|
2020-12-30 18:11:46 +08:00
|
|
|
}
|