mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-20 19:02:33 +00:00
Calculate --sidebar-wrapper-height in pure CSS (#360)
This commit is contained in:
parent
777a70b751
commit
76bba71574
@ -32,13 +32,11 @@
|
|||||||
<!--/noindex-->
|
<!--/noindex-->
|
||||||
|
|
||||||
<div class="site-overview-wrap sidebar-panel">
|
<div class="site-overview-wrap sidebar-panel">
|
||||||
<div class="site-overview">
|
|
||||||
{{ partial('_partials/sidebar/site-overview.njk', {}, {cache: theme.cache.enable}) }}
|
{{ partial('_partials/sidebar/site-overview.njk', {}, {cache: theme.cache.enable}) }}
|
||||||
|
|
||||||
{{- next_inject('sidebar') }}
|
{{- next_inject('sidebar') }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{%- if theme.back2top.enable and theme.back2top.sidebar %}
|
{%- if theme.back2top.enable and theme.back2top.sidebar %}
|
||||||
<div class="back-to-top animated" role="button" aria-label="{{ __('accessibility.back_to_top') }}">
|
<div class="back-to-top animated" role="button" aria-label="{{ __('accessibility.back_to_top') }}">
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
.sidebar-inner {
|
.sidebar-inner {
|
||||||
color: $grey-dark;
|
color: $grey-dark;
|
||||||
|
// Init Sidebar & TOC inner dimensions on all pages and for all schemes.
|
||||||
|
$offset = (($scheme == 'Pisces') or ($scheme == 'Gemini')) ? $sidebar-offset : $sidebar-padding;
|
||||||
|
max-height: 'calc(100vh - %s)' % unit($offset * 2, 'px');
|
||||||
padding: $sidebar-padding 10px;
|
padding: $sidebar-padding 10px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
flex-column();
|
||||||
|
|
||||||
.site-overview {
|
|
||||||
max-height: var(--sidebar-wrapper-height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.site-overview-item:not(:first-child) {
|
.site-overview-item:not(:first-child) {
|
||||||
|
|||||||
@ -35,8 +35,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Need for Sidebar/TOC inner scrolling if content taller then viewport.
|
||||||
.sidebar-panel-container {
|
.sidebar-panel-container {
|
||||||
max-height: var(--sidebar-wrapper-height);
|
flex: 1;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,8 +45,6 @@ NexT.boot.registerEvents = function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('resize', NexT.utils.initSidebarDimension);
|
|
||||||
|
|
||||||
window.addEventListener('hashchange', () => {
|
window.addEventListener('hashchange', () => {
|
||||||
const tHash = location.hash;
|
const tHash = location.hash;
|
||||||
if (tHash !== '' && !tHash.match(/%\S{2}/)) {
|
if (tHash !== '' && !tHash.match(/%\S{2}/)) {
|
||||||
|
|||||||
@ -273,6 +273,7 @@ NexT.utils = {
|
|||||||
}
|
}
|
||||||
// Scrolling to center active TOC element if TOC content is taller then viewport.
|
// Scrolling to center active TOC element if TOC content is taller then viewport.
|
||||||
const tocElement = document.querySelector('.sidebar-panel-container');
|
const tocElement = document.querySelector('.sidebar-panel-container');
|
||||||
|
if (!tocElement.parentNode.classList.contains('sidebar-toc-active')) return;
|
||||||
window.anime({
|
window.anime({
|
||||||
targets : tocElement,
|
targets : tocElement,
|
||||||
duration : 200,
|
duration : 200,
|
||||||
@ -281,25 +282,7 @@ NexT.utils = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Init Sidebar & TOC inner dimensions on all pages and for all schemes.
|
|
||||||
* Need for Sidebar/TOC inner scrolling if content taller then viewport.
|
|
||||||
*/
|
|
||||||
initSidebarDimension: function() {
|
|
||||||
const sidebarNav = document.querySelector('.sidebar-nav');
|
|
||||||
const sidebarb2t = document.querySelector('.sidebar-inner .back-to-top');
|
|
||||||
const sidebarNavHeight = sidebarNav ? sidebarNav.offsetHeight : 0;
|
|
||||||
const sidebarb2tHeight = sidebarb2t ? sidebarb2t.offsetHeight : 0;
|
|
||||||
const sidebarOffset = CONFIG.sidebar.offset || 12;
|
|
||||||
let sidebarSchemePadding = (CONFIG.sidebar.padding * 2) + sidebarNavHeight + sidebarb2tHeight;
|
|
||||||
if (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') sidebarSchemePadding += sidebarOffset * 2;
|
|
||||||
// Initialize Sidebar & TOC Height.
|
|
||||||
const sidebarWrapperHeight = document.body.offsetHeight - sidebarSchemePadding + 'px';
|
|
||||||
document.documentElement.style.setProperty('--sidebar-wrapper-height', sidebarWrapperHeight);
|
|
||||||
},
|
|
||||||
|
|
||||||
updateSidebarPosition: function() {
|
updateSidebarPosition: function() {
|
||||||
NexT.utils.initSidebarDimension();
|
|
||||||
if (window.innerWidth < 992 || CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') return;
|
if (window.innerWidth < 992 || CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') return;
|
||||||
// Expand sidebar on post detail page by default, when post has a toc.
|
// Expand sidebar on post detail page by default, when post has a toc.
|
||||||
const hasTOC = document.querySelector('.post-toc');
|
const hasTOC = document.querySelector('.post-toc');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user