perf: optimize header

This commit is contained in:
XPoet 2020-12-25 17:50:22 +08:00
parent d97db0dd34
commit a354adb075
4 changed files with 30 additions and 29 deletions

View File

@ -1,6 +1,6 @@
<header class="header-wrapper"> <header class="header-wrapper">
<div class="header-content"> <div class="header-content<%- (theme.style.first_screen.enable === true && is_home() && !page.prev) ? ' has-first-screen' : '' %>">
<div class="left"> <div class="left">
<a class="logo-title" href="/"> <a class="logo-title" href="/">
<%= theme.base_info.title || config.title || 'Keep theme' %> <%= theme.base_info.title || config.title || 'Keep theme' %>

View File

@ -1,5 +1,7 @@
$header-progress-height = 2.8px; $header-progress-height = 2.8px;
$logo-title-font-size = 2.2rem; $logo-title-font-size = 2.2rem;
$pc-search-icon-font-size = 1.5rem;
$menu-bar-line-height = 2.5px;
.header-wrapper { .header-wrapper {
width: 100%; width: 100%;
@ -23,12 +25,16 @@ $logo-title-font-size = 2.2rem;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
z-index: $z-index-5; z-index: $z-index-5;
transition();
&.has-first-screen {
max-width: $content-max-width * 1.2;
}
+keep-tablet() { +keep-tablet() {
width: $main-content-width-tablet; width: $main-content-width-tablet;
} }
+keep-mobile() { +keep-mobile() {
width: $main-content-width-mobile; width: $main-content-width-mobile;
} }
@ -117,12 +123,8 @@ $logo-title-font-size = 2.2rem;
&.search { &.search {
font-size: 1.5rem; font-size: $pc-search-icon-font-size;
margin-left: 26px; margin-left: 26px;
&:hover {
color: var(--primary-color);
}
} }
} }
@ -156,20 +158,11 @@ $logo-title-font-size = 2.2rem;
} }
} }
.search {
&:hover {
color: var(--primary-color);
}
}
.menu-bar { .menu-bar {
.menu-bar-middle { .menu-bar-middle {
width: 18px; width: 18px;
height: 2.6px; height: $menu-bar-line-height;
position: relative; position: relative;
background: var(--default-text-color); background: var(--default-text-color);
transition(); transition();
@ -180,7 +173,7 @@ $logo-title-font-size = 2.2rem;
top: -6px; top: -6px;
left: 0; left: 0;
width: 100%; width: 100%;
height: 2.6px; height: $menu-bar-line-height;
background: var(--default-text-color); background: var(--default-text-color);
transition(); transition();
} }
@ -191,7 +184,7 @@ $logo-title-font-size = 2.2rem;
bottom: -6px; bottom: -6px;
left: 0; left: 0;
width: 100%; width: 100%;
height: 2.6px; height: $menu-bar-line-height;
background: var(--default-text-color); background: var(--default-text-color);
transition(); transition();
} }
@ -309,8 +302,8 @@ $logo-title-font-size = 2.2rem;
.header-content { .header-content {
.left { .left {
transform: scale(0.88); transform: scale(0.86);
transform-origin: left top; transform-origin: left;
transition(); transition();
} }
@ -319,7 +312,9 @@ $logo-title-font-size = 2.2rem;
.pc { .pc {
.menu-list { .menu-list {
.menu-item { .menu-item {
a:hover { a:hover {
&::after { &::after {
bottom: -($header-shrink-height / 2 - 12); bottom: -($header-shrink-height / 2 - 12);

View File

@ -5,7 +5,7 @@
// ======================================================================== // ========================================================================
// layout // layout
// ======================================================================== // ========================================================================
$header-height = 72px; // $header-height = 76px; //
$main-content-width = 80%; // PC $main-content-width = 80%; // PC
$main-content-width-tablet = 85%; // $main-content-width-tablet = 85%; //
$main-content-width-mobile = 90%; // $main-content-width-mobile = 90%; //

View File

@ -86,13 +86,19 @@ KEEP.utils = {
contentAreaWidthAdjust() { contentAreaWidthAdjust() {
const toolExpandDom = document.querySelector('.tool-expand-width'); const toolExpandDom = document.querySelector('.tool-expand-width');
const mainContentDom = document.querySelector('.main-content');
const headerContentDom = document.querySelector('.header-content'); const headerContentDom = document.querySelector('.header-content');
const mainContentDom = document.querySelector('.main-content');
const iconDom = toolExpandDom.querySelector('i'); const iconDom = toolExpandDom.querySelector('i');
const defaultMaxWidth = KEEP.theme_config.style.content_max_width || '1000px';
const expandMaxWidth = '90%';
let headerMaxWidth = defaultMaxWidth;
let isExpand = false; let isExpand = false;
const expandWidth = '90%';
const notExpandWidth = (KEEP.theme_config.style.content_max_width || '1000px'); if (KEEP.theme_config.style.first_screen.enable === true) {
headerMaxWidth = parseInt(defaultMaxWidth) * 1.2 + 'px';
}
toolExpandDom.addEventListener('click', () => { toolExpandDom.addEventListener('click', () => {
isExpand = !isExpand; isExpand = !isExpand;
@ -100,13 +106,13 @@ KEEP.utils = {
if (isExpand) { if (isExpand) {
iconDom.classList.remove('fa-arrows-alt-h'); iconDom.classList.remove('fa-arrows-alt-h');
iconDom.classList.add('fa-compress-arrows-alt'); iconDom.classList.add('fa-compress-arrows-alt');
mainContentDom.style.maxWidth = expandWidth; headerContentDom.style.maxWidth = expandMaxWidth;
headerContentDom.style.maxWidth = expandWidth; mainContentDom.style.maxWidth = expandMaxWidth;
} else { } else {
iconDom.classList.remove('fa-compress-arrows-alt'); iconDom.classList.remove('fa-compress-arrows-alt');
iconDom.classList.add('fa-arrows-alt-h'); iconDom.classList.add('fa-arrows-alt-h');
mainContentDom.style.maxWidth = notExpandWidth; headerContentDom.style.maxWidth = headerMaxWidth;
headerContentDom.style.maxWidth = notExpandWidth; mainContentDom.style.maxWidth = defaultMaxWidth;
} }
}); });