Skip to content

Commit

Permalink
Optimize back-to-top style
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Jun 20, 2020
1 parent 5d2f92e commit b8e2ce8
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 40 deletions.
1 change: 0 additions & 1 deletion scripts/helpers/next-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ hexo.extend.helper.register('next_config', function() {
exturl : theme.exturl,
sidebar : theme.sidebar,
copycode : theme.codeblock.copy_button.enable,
back2top : theme.back2top,
bookmark : theme.bookmark,
fancybox : theme.fancybox,
mediumzoom: theme.mediumzoom,
Expand Down
6 changes: 0 additions & 6 deletions source/css/_common/components/back-to-top-sidebar.styl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
opacity: 0;
transition: opacity $transition-ease;

if (!hexo-config('back2top.scrollpercent')) {
span {
display: none;
}
}

&.back-to-top-on {
cursor: pointer;
opacity: $b2t-opacity;
Expand Down
13 changes: 0 additions & 13 deletions source/css/_common/components/back-to-top.styl
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
.back-to-top {
background: $b2t-bg-color;
bottom: $b2t-position-bottom;
box-sizing: border-box;
color: $b2t-color;
cursor: pointer;
opacity: $b2t-opacity;
padding: 0 6px;
position: fixed;
transition: bottom $transition-ease;
z-index: $zindex-3;
sidebar-toggle();

if (hexo-config('back2top.scrollpercent')) {
width: initial;
} else {
width: 24px;

span {
display: none;
}
}

&:hover {
Expand All @@ -28,8 +19,4 @@
&.back-to-top-on {
bottom: $b2t-position-bottom-on;
}

+tablet-mobile() {
opacity: $b2t-opacity-hover;
}
}
6 changes: 6 additions & 0 deletions source/css/_common/components/components.styl
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
if (hexo-config('back2top.enable')) {
.back-to-top {
font-size: $b2t-font-size;

if (!hexo-config('back2top.scrollpercent')) {
span {
display: none;
}
}
}

@import (hexo-config('back2top.sidebar') ? 'back-to-top-sidebar' : 'back-to-top');
Expand Down
2 changes: 1 addition & 1 deletion source/css/_common/outline/header/bookmark.styl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
position: fixed;
top: -10px;
transition: top .3s;
sidebar-toggle(true);
sidebar-toggle-position(true);

+tablet-mobile() {
display: none;
Expand Down
1 change: 1 addition & 0 deletions source/css/_common/outline/sidebar/sidebar-nav.styl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

.sidebar-panel {
display: none;
max-height: var(--sidebar-wrapper-height);
overflow-x: hidden;
overflow-y: auto;
}
Expand Down
8 changes: 0 additions & 8 deletions source/css/_common/outline/sidebar/sidebar-toggle.styl
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
.sidebar-toggle {
background: $black-deep;
bottom: 45px;
cursor: pointer;
height: 12px;
padding: 6px 5px;
position: fixed;
width: 14px;
z-index: $zindex-3;
sidebar-toggle();

+tablet-mobile() {
opacity: $b2t-opacity-hover;
}
}

.sidebar-toggle:hover .toggle-line {
Expand Down
2 changes: 1 addition & 1 deletion source/css/_common/outline/sidebar/sidebar.styl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.sidebar {
background: $black-deep;
bottom: 0;
if (!hexo-config('back2top.sidebar')){
if (!hexo-config('back2top.sidebar')) {
box-shadow: inset 0 2px 6px black;
}
position: fixed;
Expand Down
19 changes: 18 additions & 1 deletion source/css/_mixins.styl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ main-container() {
}
}

sidebar-toggle($reverse = false) {
sidebar-toggle-position($reverse = false) {
$condition = hexo-config('sidebar.position') == 'right';
if (($scheme == 'Muse') || ($scheme == 'Mist')) {
$condition = $condition == $reverse;
Expand All @@ -127,3 +127,20 @@ sidebar-toggle($reverse = false) {
}
}
}

sidebar-toggle() {
background: $b2t-bg-color;
cursor: pointer;
opacity: $b2t-opacity;
position: fixed;
z-index: $zindex-3;
sidebar-toggle-position();

&:hover {
opacity: $b2t-opacity-hover;
}

+tablet-mobile() {
opacity: $b2t-opacity-hover;
}
}
4 changes: 0 additions & 4 deletions source/css/_schemes/Muse/_menu.styl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
+mobile() {
border-bottom: 1px solid $grey-lighter;
border-top: 1px solid $grey-lighter;
left: 0;
margin: 0;
padding: 0;
width: 100%;
}
}

Expand Down
9 changes: 4 additions & 5 deletions source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,14 @@ NexT.utils = {
*/
initSidebarDimension: function() {
const sidebarNav = document.querySelector('.sidebar-nav');
const sidebarNavHeight = sidebarNav.style.display !== 'none' ? sidebarNav.offsetHeight : 0;
const sidebarb2t = document.querySelector('.sidebar-inner .back-to-top');
const sidebarb2tHeight = sidebarb2t ? sidebarb2t.offsetHeight : 0;
const sidebarOffset = CONFIG.sidebar.offset || 12;
const sidebarb2tHeight = CONFIG.back2top.enable && CONFIG.back2top.sidebar ? document.querySelector('.back-to-top').offsetHeight : 0;
let sidebarSchemePadding = (CONFIG.sidebar.padding * 2) + sidebarNavHeight + sidebarb2tHeight;
let sidebarSchemePadding = CONFIG.sidebar.padding * 2 + sidebarNav.offsetHeight + sidebarb2tHeight;
if (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') sidebarSchemePadding += sidebarOffset * 2;
// Initialize Sidebar & TOC Height.
const sidebarWrapperHeight = document.body.offsetHeight - sidebarSchemePadding + 'px';
document.querySelector('.site-overview-wrap').style.maxHeight = sidebarWrapperHeight;
document.querySelector('.post-toc-wrap').style.maxHeight = sidebarWrapperHeight;
document.documentElement.style.setProperty('--sidebar-wrapper-height', sidebarWrapperHeight);
},

updateSidebarPosition: function() {
Expand Down

0 comments on commit b8e2ce8

Please sign in to comment.