Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions source/css/_common/outline/sidebar/sidebar-toc.styl
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,18 @@ if (hexo-config('toc.enable')) {
.nav {
if (not hexo-config('toc.expand_all')) {
.nav-child {
--height: 0;
height: 0;
opacity: 0;
overflow: hidden;
transition-property: height, opacity, visibility;
transition-property: height, opacity;
transition: $transition-ease;
Comment on lines +40 to 41
Copy link

Copilot AI Jul 25, 2025

Choose a reason for hiding this comment

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

Removing visibility from the transition properties may cause visual glitches during the animation. The visibility property was likely included to ensure smooth show/hide transitions. Consider testing thoroughly across different browsers to ensure the animation remains smooth without it.

Suggested change
transition-property: height, opacity;
transition: $transition-ease;
transition-property: height, opacity, visibility;
transition: $transition-ease;
visibility: hidden;

Copilot uses AI. Check for mistakes.

visibility: hidden;
}

.active > .nav-child {
height: var(--height, auto);
height: auto;
// https://caniuse.com/mdn-css_types_calc-size
height: calc-size(auto, size);
opacity: 1;
visibility: unset;
}
}

Expand Down
18 changes: 1 addition & 17 deletions source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,24 +352,16 @@ NexT.utils = {
const target = navItemList[index];
if (!target || target.classList.contains('active-current')) return;

const singleHeight = navItemList[navItemList.length - 1].offsetHeight;

nav.querySelectorAll('.active').forEach(navItem => {
navItem.classList.remove('active', 'active-current');
});
target.classList.add('active', 'active-current');

let activateEle = target.querySelector('.nav-child') || target.parentElement;
let navChildHeight = 0;

while (nav.contains(activateEle)) {
if (activateEle.classList.contains('nav-item')) {
activateEle.classList.add('active');
} else { // .nav-child or .nav
// scrollHeight isn't reliable for transitioning child items.
// The last nav-item in a list has a margin-bottom of 5px.
navChildHeight += (singleHeight * activateEle.childElementCount) + 5;
activateEle.style.setProperty('--height', `${navChildHeight}px`);
}
activateEle = activateEle.parentElement;
}
Expand Down Expand Up @@ -408,16 +400,8 @@ NexT.utils = {
const tocPanel = panelContainer.firstElementChild;
const overviewPanel = panelContainer.lastElementChild;

let postTOCHeight = tocPanel.scrollHeight;
// For TOC activation, try to use the animated TOC height
if (index === 0) {
const nav = tocPanel.querySelector('.nav');
if (nav) {
postTOCHeight = parseInt(nav.style.getPropertyValue('--height'), 10);
}
}
const panelHeights = [
postTOCHeight,
tocPanel.scrollHeight,
overviewPanel.scrollHeight
];
panelContainer.style.setProperty('--inactive-panel-height', `${panelHeights[1 - index]}px`);
Expand Down
Loading