update: header 样式 && fix: header收缩因高度不够产生的bug

This commit is contained in:
XPoet 2020-04-01 15:28:01 +08:00
parent 484c1e4321
commit 7078630641
10 changed files with 176 additions and 266 deletions

View File

@ -2,15 +2,18 @@
<div class="header-content">
<a class="logo vertical-center" href="/">
<a class="logo-title vertical-center" href="/">
<%= config.title %>
</a>
<ul class="menu-list vertical-center">
<% for (let i in theme.menu) { %>
<li class="menu-item">
<a class="<%- isInHomePaging(page.path, theme.menu[i]) ? 'current' : is_current(theme.menu[i]) ? 'current' : '' %>"
href="<%- url_for(theme.menu[i]) %>"><%= __(i.toLowerCase()) %></a>
<a class="<%- isInHomePaging(page.path, theme.menu[i]) ? 'active' : is_current(theme.menu[i]) ? 'active' : '' %>"
href="<%- url_for(theme.menu[i]) %>"
>
<%= __(i.toLowerCase()).toUpperCase() %>
</a>
</li>
<% } %>
<% if (theme.local_search.enable) { %>

View File

@ -5,7 +5,7 @@
</div>
<div class="about-comments">
<% if (page.comments) { %>
<%- partial('common/valine') %>
<%- partial('_partial/valine') %>
<% } %>
</div>
</div>

View File

@ -17,4 +17,4 @@ const postList = createNewArchivePosts(is_archive() ? site.posts : page.posts)
</ul>
</section>
<% }) %>
</div>
</div>

View File

@ -1,103 +1,36 @@
<div class="home-content-container">
<!-- 左侧边栏-->
<div class="left-sidebar">
<!-- 文章列表 -->
<!--<ul class="active-list">
<% for(let i = 0; i < 8; i++) { %>
<li class="active-item">
<h2 class="title">
<a href="/">
这个世界很苦,但你要很甜
</a>
</h2>
<p class="summary">
在薄情的世界里深情的活着。 01 昨天,许久没找我聊天的外甥女,突然发个大哭的表情过来说,小姨,我要活不下去了。
我知道在上高二的她,能让她大悲大喜的事情,除了考试成绩还是考...
</p>
<div class="meta-info">
<span class="date meta-info-item">
<i class="fa fa-calendar"></i> 2020-03-31 08:55:00
</span>
<span class="tags meta-info-item">
<i class="fa fa-tags"></i>TS
</span>
<span class="views meta-info-item">
<i class="fa fa-eye"></i>1234
</span>
</div>
</li>
<% } %>
</ul>-->
<div class="home-container">
<ul class="article-post-list">
<% page.posts.forEach(post => { %>
<li class="article-post-item">
<div class="article-post-title">
<h3>
<a class="article-title-hover-animation" href="<%- url_for(post.path) %>"><%= post.title %></a>
</h3>
</div>
<div class="article-post-content">
<%- truncate(strip_html(post.content), {length: 150}) %>
</div>
<div class="article-post-meta-info">
<%- partial('_partial/article-meta-info', {articleObject: post, index: true}) %>
</div>
</li>
<% }) %>
</ul>
<div class="paginator">
<% if (page.prev) { %>
<a class="prev btn"
href="<%- url_for(page.prev == 1 ? '' : '/page/' + page.prev) %>"
><%- __('prev') %></a>
<% } %>
<% if (page.next) { %>
<a class="next btn"
href="<%- url_for('/page/' + page.next) %>"
><%- __('next') %></a>
<% } %>
</div>
</div>
</div>
<!-- 右侧边栏 -->
<div class="right-sidebar">
<!-- 友情链接 -->
<!--<div class="friend-link">
<div class="friend-link-title">
<span>友情链接</span>
<a class="page-change" href=""><i class="fa fa-refresh"></i> 换一批</a>
<ul class="home-article-list">
<% page.posts.forEach(post => { %>
<li class="home-article-item">
<div class="home-article-title">
<h3>
<a class="article-title-hover-animation" href="<%- url_for(post.path) %>"><%= post.title %></a>
</h3>
</div>
<ul class="friend-link-list">
<% for(let i = 0; i < 5; i++){ %>
<li class="friend-link-item">
<div class="avatar-box">
<%- image_tag(theme.avatar, {class: 'avatar'}) %>
</div>
<a class="go-friend-link" target="_blank" href="">+前往探索</a>
<a class="friend-name" href="">X诗人</a>
<p class="friend-intro">代码如诗,代码如诗</p>
</li>
<% } %>
</ul>
<div class="view-more">
查看更多
<div class="home-article-content">
<%- truncate(strip_html(post.content), {length: 150}) %>
</div>
</div>-->
<div class="home-article-meta-info">
<%- partial('_partial/article-meta-info', {articleObject: post, index: true}) %>
</div>
</li>
<% }) %>
</ul>
<div class="paginator">
<% if (page.prev) { %>
<a class="prev btn"
href="<%- url_for(page.prev == 1 ? '' : '/page/' + page.prev) %>"
><%- __('prev') %></a>
<% } %>
<% if (page.next) { %>
<a class="next btn"
href="<%- url_for('/page/' + page.next) %>"
><%- __('next') %></a>
<% } %>
</div>
</div>
</div>

View File

@ -1,4 +1,5 @@
@require "../common/variables.styl"
@import "../common/root.styl"
.header-wrapper {
width: 100%;
@ -23,21 +24,76 @@
transform: translateY(-50%);
}
.logo {
.logo-title {
left: 0;
font-size: 28px;
font-weight: bold;
color: #555;
&::after {
content: '';
position: absolute;
bottom: -12px;
left: 0;
width: 40px;
height: 2px;
background: $a-hover-color;
transition: all 0.5s ease;
}
}
.menu-list {
right: 0;
li {
.menu-item {
float: left;
margin-left: 20px;
font-size: 14px;
position: relative;
margin-left: 30px;
&:first-child {
margin-left: 0;
}
a {
&:hover {
&::after {
content: '';
position: absolute;
bottom: -10px;
left: 50%;
width: 100%;
height: 2px;
transform: translateX(-50%);
background: $a-hover-color;
transition: all 0.5s ease;
}
}
}
.active {
color: #555;
font-weight: 700;
transition: all 0.5s ease;
&::after {
content: '';
position: absolute;
bottom: -10px;
left: 50%;
width: 100%;
height: 2px;
transform: translateX(-50%);
background: $a-hover-color;
transition: all 0.5s ease;
}
}
}
}
@ -84,7 +140,7 @@
.drawer-menu-active {
background: #f45a6f;
background: $a-hover-color;
color: white;
}
@ -141,9 +197,38 @@
background: #fff;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
.header-content {
.logo-title {
&::after {
opacity: 0;
}
}
.menu-list {
.menu-item {
a:hover {
&::after {
bottom: -22px;
}
}
.active::after {
bottom: -22px;
}
}
}
}
.header-drawer {
padding: $header-shrink-height 0 20px 0;
}
}

View File

@ -72,7 +72,7 @@ a:hover, a:active {
position: absolute;
width: 100%;
height: 2px;
bottom: 0;
bottom: -2px;
left: 0;
background-color: $article-title-color;
visibility: hidden;

View File

@ -1,165 +1,54 @@
@require "common/variables.styl"
.home-content-container {
.left-sidebar {
float: left;
width: 70%;
/*.active-list {
.home-article-list {
.active-item {
padding-bottom: 30px;
margin-top: 10px;
border-bottom: 1px solid #eee;
.home-article-item {
.meta-info {
font-size: 12px;
margin-bottom: 30px;
padding-bottom: 30px;
border-bottom: 1px solid $border-color;
.meta-info-item {
margin-right: 5px;
}
.home-article-title {
h3 {
font-weight: 600;
color: $article-title-color;
font-size: 22px;
margin: 0;
}
a {
color: $article-title-color;
}
}
}*/
.home-container {
.article-post-list {
.article-post-item {
margin-bottom: 30px;
padding-bottom: 30px;
border-bottom: 1px solid $border-color;
.article-post-title {
h3 {
font-weight: 600;
color: $article-title-color;
font-size: 22px;
margin: 0;
}
a {
color: $article-title-color;
}
}
.article-post-content {
padding: 15px 0;
line-height: 2em;
}
}
}
.paginator {
padding-bottom: 40px;
.page-number {
display: none !important;
}
a.prev {
float: left;
}
a.next {
float: right;
}
}
}
}
.right-sidebar {
float: right;
width: 30%;
/*.friend-link {
text-align: center;
border: 1px solid #eeeeee;
.friend-link-title {
text-align: left;
.page-change {
float: right;
display: inline-block;
font-size: 14px;
color: #969696;
}
}
.friend-link-list {
margin: 0 0 20px;
text-align: left;
.friend-link-item {
margin-top: 15px;
.avatar-box {
float: left;
width: 48px;
height: 48px;
margin-right: 10px;
img.avatar {
width: 100%;
height: 100%;
border-radius: 2px;
}
}
.go-friend-link {
float: right;
margin-top: 2px;
padding: 0;
font-size: 13px;
color: #42c02e;
}
.friend-name {
padding-top: 2px;
margin-right: 60px;
font-size: 14px;
display: block;
}
p.friend-intro {
margin-top: 2px;
font-size: 12px;
color: #969696;
}
}
}
.view-more {
left: 0;
width: 100%;
font-size: 13px;
color: #787878;
background-color: #f7f7f7;
border: 1px solid #dcdcdc;
border-radius: 4px;
.home-article-content {
padding: 15px 0;
line-height: 2em;
}
}
*/
}
.paginator {
padding-bottom: 40px;
.page-number {
display: none !important;
}
a.prev {
float: left;
}
a.next {
float: right;
}
}
}

View File

@ -22,6 +22,7 @@
width: 80%;
height: 100%;
position: relative;
padding: 20px 0;
}

View File

@ -1,4 +1,3 @@
//@import "layout/variables.styl"
@import "libs/font-awesome.min.css"
@import "layout/common/animated.styl"
@import "layout/common/basic.styl"

View File

@ -1,19 +1,19 @@
let isHeaderShrink = false;
let header = document.querySelector('.header-wrapper');
let pageTemplateContainer = document.querySelector('.page-template');
let menuBar = document.querySelector('.menu-bar');
let windowMask = document.querySelector('.window-mask');
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;
window.addEventListener('scroll', function (e) {
var scrollTop = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
if (!isHeaderShrink && scrollTop > 10) {
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 <= 10) {
} else if (isHeaderShrink && scrollTop <= headerHeight) {
isHeaderShrink = false;
header.classList.remove('header-wrapper-shrink');
pageTemplateContainer.classList.remove('page-top-shrink');