From d17420b8a246cdd5943e14b1cf753f18712e6dab Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Fri, 19 Jun 2020 09:34:33 +0800 Subject: [PATCH] New mixin sidebar-toggle --- .../components/back-to-top-sidebar.styl | 1 - source/css/_common/components/back-to-top.styl | 3 +-- .../css/_common/outline/header/bookmark.styl | 2 +- .../outline/sidebar/sidebar-toggle.styl | 3 +-- source/css/_mixins.styl | 18 ++++++++++++++++++ source/css/_schemes/Muse/_sidebar.styl | 13 ------------- source/css/_schemes/Pisces/_layout.styl | 13 ------------- source/css/_variables/base.styl | 4 ++-- source/js/utils.js | 3 +-- 9 files changed, 24 insertions(+), 36 deletions(-) diff --git a/source/css/_common/components/back-to-top-sidebar.styl b/source/css/_common/components/back-to-top-sidebar.styl index a1ba94b..985c03e 100644 --- a/source/css/_common/components/back-to-top-sidebar.styl +++ b/source/css/_common/components/back-to-top-sidebar.styl @@ -1,5 +1,4 @@ .back-to-top { - background: transparent; margin: 20px - $sidebar-offset -10px -20px; opacity: 0; transition: opacity $transition-ease; diff --git a/source/css/_common/components/back-to-top.styl b/source/css/_common/components/back-to-top.styl index e54bd33..8d2956e 100644 --- a/source/css/_common/components/back-to-top.styl +++ b/source/css/_common/components/back-to-top.styl @@ -4,12 +4,12 @@ box-sizing: border-box; color: $b2t-color; cursor: pointer; - left: $b2t-position-right; 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; @@ -30,7 +30,6 @@ } +tablet-mobile() { - left: $b2t-position-right-mobile; opacity: $b2t-opacity-hover; } } diff --git a/source/css/_common/outline/header/bookmark.styl b/source/css/_common/outline/header/bookmark.styl index b391f45..7427762 100644 --- a/source/css/_common/outline/header/bookmark.styl +++ b/source/css/_common/outline/header/bookmark.styl @@ -1,9 +1,9 @@ .book-mark-link { border-bottom: none; position: fixed; - right: $b2t-position-right; top: -10px; transition: top .3s; + sidebar-toggle(true); +tablet-mobile() { display: none; diff --git a/source/css/_common/outline/sidebar/sidebar-toggle.styl b/source/css/_common/outline/sidebar/sidebar-toggle.styl index 5c88037..97742a0 100644 --- a/source/css/_common/outline/sidebar/sidebar-toggle.styl +++ b/source/css/_common/outline/sidebar/sidebar-toggle.styl @@ -3,14 +3,13 @@ bottom: 45px; cursor: pointer; height: 14px; - left: $b2t-position-right; padding: 5px; position: fixed; width: 14px; z-index: $zindex-3; + sidebar-toggle(); +tablet-mobile() { - left: $b2t-position-right-mobile; opacity: $b2t-opacity-hover; if (!hexo-config('sidebar.onmobile')) { diff --git a/source/css/_mixins.styl b/source/css/_mixins.styl index 3e7afc1..14df7f3 100644 --- a/source/css/_mixins.styl +++ b/source/css/_mixins.styl @@ -109,3 +109,21 @@ main-container() { width: $content-desktop-largest; } } + +sidebar-toggle($reverse = false) { + $condition = hexo-config('sidebar.position') == 'right'; + if (($scheme == 'Muse') || ($scheme == 'Mist')) { + $condition = $condition == $reverse; + } + if ($condition) { + left: $b2t-position-right; + +tablet-mobile() { + left: $b2t-position-right-mobile; + } + } else { + right: $b2t-position-right; + +tablet-mobile() { + right: $b2t-position-right-mobile; + } + } +} diff --git a/source/css/_schemes/Muse/_sidebar.styl b/source/css/_schemes/Muse/_sidebar.styl index 47ffec3..525ed3e 100644 --- a/source/css/_schemes/Muse/_sidebar.styl +++ b/source/css/_schemes/Muse/_sidebar.styl @@ -12,19 +12,6 @@ if (hexo-config('sidebar.position') == 'right') { right: 0; } } - - .sidebar-toggle, .back-to-top { - left: auto; - right: $b2t-position-right; - - +tablet-mobile() { - right: $b2t-position-right-mobile; - } - } - - .book-mark-link { - left: $b2t-position-right; - } } else { .sidebar-active { +desktop() { diff --git a/source/css/_schemes/Pisces/_layout.styl b/source/css/_schemes/Pisces/_layout.styl index 1c01d7a..8886c46 100644 --- a/source/css/_schemes/Pisces/_layout.styl +++ b/source/css/_schemes/Pisces/_layout.styl @@ -74,10 +74,6 @@ if (hexo-config('sidebar.position') == 'right') { right: 0; } - .book-mark-link { - left: $b2t-position-right; - } - .footer-inner { padding-right: $sidebar-desktop + $sidebar-offset; } @@ -85,15 +81,6 @@ if (hexo-config('sidebar.position') == 'right') { .footer-inner { padding-left: $sidebar-desktop + $sidebar-offset; } - - .back-to-top { - left: auto; - right: $b2t-position-right; - - +tablet-mobile() { - right: $b2t-position-right-mobile; - } - } } .footer-inner { diff --git a/source/css/_variables/base.styl b/source/css/_variables/base.styl index 6b8086e..d497754 100644 --- a/source/css/_variables/base.styl +++ b/source/css/_variables/base.styl @@ -263,8 +263,8 @@ $site-state-item-name-color = inherit; // Components // -------------------------------------------------- // Back to top -$b2t-opacity = 1; -$b2t-opacity-hover = .8; +$b2t-opacity = .8; +$b2t-opacity-hover = 1; $b2t-position-bottom = -100px; $b2t-position-bottom-on = 19px; $b2t-position-right = 30px; diff --git a/source/js/utils.js b/source/js/utils.js index bfc8d21..a9bdb31 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -321,8 +321,7 @@ NexT.utils = { 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; - // Margin of sidebar b2t: -4px -10px -18px, brings a different of 22px. - if (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') sidebarSchemePadding += (sidebarOffset * 2) - 22; + 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;