Skip to content

Commit

Permalink
Optimize sidebar-panel animation
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Jul 12, 2020
1 parent dca900a commit 1b00414
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions source/js/next-boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ NexT.boot.registerEvents = function() {
}));
});

const TAB_ANIMATE_DURATION = 200;
const duration = 200;
document.querySelectorAll('.sidebar-nav li').forEach((element, index) => {
element.addEventListener('click', event => {
const item = event.currentTarget;
Expand All @@ -53,20 +53,21 @@ NexT.boot.registerEvents = function() {
const activeClassName = ['sidebar-toc-active', 'sidebar-overview-active'];

window.anime({
targets : panel[1 - index],
duration: TAB_ANIMATE_DURATION,
easing : 'linear',
opacity : 0,
complete: () => {
duration,
targets : panel[1 - index],
easing : 'linear',
opacity : 0,
translateY: [0, -20],
complete : () => {
// Prevent adding TOC to Overview if Overview was selected when close & open sidebar.
sidebar.classList.remove(activeClassName[1 - index]);
panel[index].style.opacity = 0;
sidebar.classList.add(activeClassName[index]);
window.anime({
targets : panel[index],
duration: TAB_ANIMATE_DURATION,
easing : 'linear',
opacity : 1
duration,
targets : panel[index],
easing : 'linear',
opacity : [0, 1],
translateY: [-20, 0],
});
}
});
Expand All @@ -88,7 +89,7 @@ NexT.boot.refresh = function() {

/**
* Register JS handlers by condition option.
* Need to add config option in Front-End at 'layout/_partials/head.njk' file.
* Need to add config option in Front-End at 'scripts/helpers/next-config.js' file.
*/
CONFIG.prism && window.Prism.highlightAll();
CONFIG.fancybox && NexT.utils.wrapImageWithFancyBox();
Expand Down

1 comment on commit 1b00414

@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.