Skip to content

Commit

Permalink
Feature: Close sidebar when click any blank part (theme-next#607)
Browse files Browse the repository at this point in the history
* Fix theme-next#606

* Add sidebar.dimmer option
  • Loading branch information
stevenjoezhang authored Feb 23, 2019
1 parent d2103a6 commit ebc0e3e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
5 changes: 3 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ sidebar:
position: left
#position: right

# Manual define the sidebar width.
# If commented, will be default for:
# Manual define the sidebar width. If commented, will be default for:
# Muse | Mist: 320
# Pisces | Gemini: 240
#width: 300
Expand All @@ -259,6 +258,8 @@ sidebar:
scrollpercent: false
# Enable sidebar on narrow view (only for Muse | Mist).
onmobile: false
# Click any blank part of the page to close sidebar (only for Muse | Mist).
dimmer: false


# ---------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions layout/_macro/sidebar.swig
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
</div>

<aside id="sidebar" class="sidebar">
{% if theme.sidebar.onmobile %}
<div id="sidebar-dimmer"></div>
{% endif %}
<div class="sidebar-inner">

{% set display_toc = is_post and theme.toc.enable or is_page and theme.toc.enable %}
Expand Down Expand Up @@ -186,4 +183,7 @@

</div>
</aside>
{% if theme.sidebar.dimmer %}
<div id="sidebar-dimmer"></div>
{% endif %}
{% endmacro %}
21 changes: 9 additions & 12 deletions source/css/_common/components/sidebar/sidebar-dimmer.styl
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
.sidebar-active #sidebar-dimmer {
opacity: .7;
-webkit-transform: translateX(-150%);
transform: translateX(-150%);
transition: opacity .2s;
.sidebar-active + #sidebar-dimmer {
+mobile() {
opacity: .7;
transition: opacity .5s;
}
transform: translateX(-100%);
}

#sidebar-dimmer {
display: none;
position: absolute;
display: block;
position: fixed;
top: 0;
left: 100%;
width: 200%;
width: 100%;
height: 100%;
background: #000;
opacity: 0;
transition: opacity .2s,transform 0s .2s;
+mobile() {
display: block;
}
}
2 changes: 1 addition & 1 deletion source/css/_common/components/sidebar/sidebar.styl
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@
@import "sidebar-blogroll";
@import "sidebar-nav";
@import "sidebar-toc";
@import "sidebar-dimmer" if hexo-config('sidebar.onmobile');
@import "sidebar-dimmer" if hexo-config('sidebar.dimmer');

0 comments on commit ebc0e3e

Please sign in to comment.