hexo-theme-keep/source/js/common.js

29 lines
1.1 KiB
JavaScript
Raw Normal View History

let isHeaderShrink = false;
const header = document.querySelector('.header-wrapper');
const pageTemplateContainer = document.querySelector('.page-template');
const menuBar = document.querySelector('.menu-bar');
const windowMask = document.querySelector('.window-mask');
const headerHeight = header.getBoundingClientRect().height;
2020-04-02 22:07:55 +08:00
window.addEventListener('scroll', function (_e) {
const scrollTop = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
if (!isHeaderShrink && scrollTop > headerHeight) {
isHeaderShrink = true;
header.classList.add('header-wrapper-shrink');
pageTemplateContainer.classList.add('page-top-shrink');
} else if (isHeaderShrink && scrollTop <= headerHeight) {
isHeaderShrink = false;
header.classList.remove('header-wrapper-shrink');
pageTemplateContainer.classList.remove('page-top-shrink');
}
});
2020-04-02 22:07:55 +08:00
menuBar.addEventListener('click', function (_e) {
header.classList.toggle('header-drawer-show');
});
2020-04-02 22:07:55 +08:00
windowMask.addEventListener('click', function (_e) {
header.classList.toggle('header-drawer-show');
2020-04-02 22:07:55 +08:00
});