Skip to content

Commit

Permalink
Use position: sticky
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Jun 16, 2020
1 parent b01a4ed commit b9968b6
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 99 deletions.
1 change: 0 additions & 1 deletion layout/_scripts/schemes/gemini.njk
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
{{- next_js('schemes/pisces.js') }}
1 change: 0 additions & 1 deletion layout/_scripts/schemes/pisces.njk
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
{{- next_js('schemes/pisces.js') }}
1 change: 1 addition & 0 deletions source/css/_schemes/Pisces/_layout.styl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
}

.content-wrap {
align-self: stretch;
background: var(--content-bg-color);
border-radius: $border-radius-inner;
box-shadow: $box-shadow-inner;
Expand Down
17 changes: 6 additions & 11 deletions source/css/_schemes/Pisces/_sidebar.styl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.sidebar {
background: var(--body-bg-color);
// Make sure that .content-wrap and .sidebar are the same height
// Required for .sidebar-inner `position: sticky;`
align-self: stretch;
background: initial;
box-shadow: none;
margin-top: 100%;
position: static;
width: $sidebar-desktop;

Expand All @@ -20,20 +22,13 @@
box-shadow: $box-shadow;
box-sizing: border-box;
color: var(--text-color);
position: sticky;
top: $sidebar-offset;
width: $sidebar-desktop;

if (hexo-config('motion.enable') && hexo-config('motion.transition.sidebar')) {
opacity: 0;
}

&.affix {
position: fixed;
top: $sidebar-offset;
}

&.affix-bottom {
position: absolute;
}
}

.site-state-item a {
Expand Down
9 changes: 9 additions & 0 deletions source/js/next-boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ NexT.boot.registerEvents = function() {
target && target.click();
}
});

if (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') {
NexT.utils.setAffixParam();
window.matchMedia('(min-width: 992px)').addListener(event => {
if (event.matches) {
NexT.utils.setAffixParam();
}
});
}
};

NexT.boot.refresh = function() {
Expand Down
86 changes: 0 additions & 86 deletions source/js/schemes/pisces.js

This file was deleted.

7 changes: 7 additions & 0 deletions source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,13 @@ NexT.utils = {
}
},

setAffixParam: function() {
const sidebarOffset = CONFIG.sidebar.offset || 12;
const headerOffset = document.querySelector('.header-inner').offsetHeight;

document.querySelector('.sidebar-inner').style.marginTop = headerOffset + sidebarOffset + 'px';
},

getScript: function(url, callback, condition) {
if (condition) {
callback();
Expand Down

1 comment on commit b9968b6

@stevenjoezhang
Copy link
Member Author

Choose a reason for hiding this comment

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

Please sign in to comment.