Skip to content

Commit

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

* Add sidebar.dimmer option
  • Loading branch information
stevenjoezhang authored Feb 23, 2019
1 parent 716f593 commit f4b967e
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');

3 comments on commit f4b967e

@sli1989
Copy link
Collaborator

@sli1989 sli1989 commented on f4b967e Apr 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but with dimmer, when i want to click into the menu or other external url, one more clicking is needed.
Can it be avoided?

@stevenjoezhang
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to rewrite some js script, I think. Listening to the click event of body, and judge if the user clicked the blank part or the menu

@stevenjoezhang
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another issue about sidebar: iissnan/hexo-theme-next#442

Please sign in to comment.