mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-18 18:33:42 +00:00
Use CSS transitions to animate site-nav (#223)
This commit is contained in:
parent
eca3ed3443
commit
be4d3bb6d9
@ -19,10 +19,6 @@
|
||||
|
||||
.site-nav {
|
||||
+mobile() {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.site-nav-on & {
|
||||
display: block;
|
||||
site-nav-hide-by-default();
|
||||
}
|
||||
}
|
||||
|
||||
@ -219,3 +219,18 @@ toggle-close($position) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
site-nav-hide-by-default() {
|
||||
--scroll-height: 0;
|
||||
height: 0;
|
||||
overflow: hidden;
|
||||
transition: height $transition-ease;
|
||||
|
||||
body:not(.site-nav-on) & .animated {
|
||||
animation: none;
|
||||
}
|
||||
|
||||
body.site-nav-on & {
|
||||
height: var(--scroll-height);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
.site-nav {
|
||||
+tablet() {
|
||||
display: none;
|
||||
site-nav-hide-by-default();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -12,35 +12,8 @@ NexT.boot.registerEvents = function() {
|
||||
event.currentTarget.classList.toggle('toggle-close');
|
||||
const siteNav = document.querySelector('.site-nav');
|
||||
if (!siteNav) return;
|
||||
const animateAction = document.body.classList.contains('site-nav-on');
|
||||
const height = NexT.utils.getComputedStyle(siteNav);
|
||||
siteNav.style.height = animateAction ? height : 0;
|
||||
const toggle = () => document.body.classList.toggle('site-nav-on');
|
||||
const begin = () => {
|
||||
siteNav.style.overflow = 'hidden';
|
||||
};
|
||||
const complete = () => {
|
||||
siteNav.style.overflow = '';
|
||||
siteNav.style.height = '';
|
||||
};
|
||||
window.anime(Object.assign({
|
||||
targets : siteNav,
|
||||
duration: 200,
|
||||
height : animateAction ? [height, 0] : [0, height],
|
||||
easing : 'linear'
|
||||
}, animateAction ? {
|
||||
begin,
|
||||
complete: () => {
|
||||
complete();
|
||||
toggle();
|
||||
}
|
||||
} : {
|
||||
begin: () => {
|
||||
begin();
|
||||
toggle();
|
||||
},
|
||||
complete
|
||||
}));
|
||||
siteNav.style.setProperty('--scroll-height', siteNav.scrollHeight + 'px');
|
||||
document.body.classList.toggle('site-nav-on');
|
||||
});
|
||||
|
||||
const duration = 200;
|
||||
|
||||
@ -290,17 +290,6 @@ NexT.utils = {
|
||||
});
|
||||
},
|
||||
|
||||
getComputedStyle: function(element) {
|
||||
const clone = element.cloneNode(true);
|
||||
clone.style.position = 'absolute';
|
||||
clone.style.visibility = 'hidden';
|
||||
clone.style.display = 'block';
|
||||
element.parentNode.appendChild(clone);
|
||||
const height = clone.clientHeight;
|
||||
element.parentNode.removeChild(clone);
|
||||
return height;
|
||||
},
|
||||
|
||||
/**
|
||||
* Init Sidebar & TOC inner dimensions on all pages and for all schemes.
|
||||
* Need for Sidebar/TOC inner scrolling if content taller then viewport.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user