Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animate nav item and panel activation #323

Merged
merged 29 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7ebac3e
Animate nav item activation
PaperStrike Jul 5, 2021
b796e87
Animate nav panel changes by CSS
PaperStrike Jul 21, 2021
7ead651
More reliable toc panel height
PaperStrike Jul 22, 2021
dbf6d1b
Merge remote-tracking branch 'upstream/master' into nav-transition
PaperStrike Feb 6, 2023
603bf11
Fix some errors in the previous merge
PaperStrike Feb 6, 2023
f28b6c8
More reliable panel heights
PaperStrike Feb 6, 2023
1dede13
Keep a placeholder for pages with no TOC
PaperStrike Feb 6, 2023
9f14c5f
Fix initial load animations
PaperStrike Feb 6, 2023
64fe64b
Fix overview padding on pages without TOC
PaperStrike Feb 6, 2023
2aa06f1
Some simple cleaning
PaperStrike Feb 6, 2023
0b9de35
Prevent placeholder TOC changes in pjax switch
PaperStrike Feb 7, 2023
200977a
Remove overflowed transform transition
PaperStrike Feb 7, 2023
9183008
Fix the comment on transform condition
PaperStrike Feb 7, 2023
3c8a0d8
Fix the comment on the TOC transform delay
PaperStrike Feb 7, 2023
4fa30e4
Remove empty check in activateSidebarPanel
PaperStrike Feb 7, 2023
024bb9a
Differentiate .placeholder-toc in more cases
PaperStrike Feb 8, 2023
ef82237
Simplify nav child height calculation
PaperStrike Feb 8, 2023
ba47edd
Align nav transition/animation durations
PaperStrike Feb 11, 2023
f0aeb4f
Transition nav color changes
PaperStrike Feb 9, 2023
e8c1cc9
Calculate nav height in pure CSS
PaperStrike Feb 11, 2023
f2d19ba
Fix inactive panel height on initial load
PaperStrike Feb 11, 2023
28235d9
Align animation/transition timing function
PaperStrike Feb 11, 2023
6cd4be8
Align missed transition timing function
PaperStrike Feb 17, 2023
f406391
Remove a duplicated prop
PaperStrike Feb 17, 2023
5022ce9
Fix hidden panel being focusable
PaperStrike Feb 17, 2023
bf7bfb5
Fix hidden nav item being focusable
PaperStrike Feb 17, 2023
2e7977f
Fix fading/hidden nav being accessiable
PaperStrike Feb 17, 2023
81d0ef8
Fix panel CSS prop order
PaperStrike Feb 17, 2023
060bdda
Remove unneeded visibility transition delays
PaperStrike Feb 18, 2023
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
30 changes: 17 additions & 13 deletions source/css/_common/outline/sidebar/sidebar-toc.styl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
ol {
list-style: none;
margin: 0;
padding: 0 2px 5px 10px;
padding: 0 2px 0 10px;
text-align: left;

> :last-child {
margin-bottom: 5px;
}

> ol {
padding-left: 0;
}
Expand All @@ -27,19 +31,19 @@
}

.nav {
.nav-child {
display: hexo-config('toc.expand_all') ? block : none;
}

.active > .nav-child {
display: block;
}

.active-current > .nav-child {
display: block;
if (not hexo-config('toc.expand_all')) {
.nav-child {
--height: 0;
height: 0;
opacity: 0;
overflow: hidden;
transition-property: height, opacity;
transition: $transition-ease;
}

> .nav-item {
display: block;
.active > .nav-child {
height: var(--height, auto);
opacity: 1;
}
}

Expand Down
30 changes: 23 additions & 7 deletions source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,18 +291,34 @@ NexT.utils = {
},

activateNavByIndex: function(index) {
const target = document.querySelectorAll('.post-toc li a.nav-link')[index];
const nav = document.querySelector('.post-toc .nav');
if (!nav) return;

const navItemList = nav.querySelectorAll('.nav-item');
const target = navItemList[index];
if (!target || target.classList.contains('active-current')) return;

document.querySelectorAll('.post-toc .active').forEach(element => {
element.classList.remove('active', 'active-current');
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 parent = target.parentNode;
while (!parent.matches('.post-toc')) {
if (parent.matches('li')) parent.classList.add('active');
parent = parent.parentNode;

let activateEle = target.querySelector('.nav-child') || target.parentElement;
let navChildHeight = 0;
while (activateEle !== nav) {
if (activateEle.classList.contains('nav-item')) {
activateEle.classList.add('active');
} else if (activateEle.classList.contains('nav-child')) {
const extraHeight = activateEle.scrollHeight
- [...activateEle.children].reduce((a, b) => a + b.offsetHeight, 0);
navChildHeight += (singleHeight * activateEle.childElementCount) + extraHeight;
activateEle.style.setProperty('--height', `${navChildHeight}px`);
}
activateEle = activateEle.parentElement;
}

// Scrolling to center active TOC element if TOC content is taller then viewport.
const tocElement = document.querySelector('.sidebar-panel-container');
window.anime({
Expand Down