mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-18 18:33:42 +00:00
Refactor site-nav animation: drop Velocity
This commit is contained in:
parent
9781cf0181
commit
659347cc1e
@ -1,4 +1,4 @@
|
||||
/* global NexT, CONFIG, Velocity */
|
||||
/* global NexT, CONFIG */
|
||||
|
||||
NexT.boot = {};
|
||||
|
||||
@ -12,18 +12,35 @@ NexT.boot.registerEvents = function() {
|
||||
event.currentTarget.classList.toggle('toggle-close');
|
||||
const siteNav = document.querySelector('.site-nav');
|
||||
if (!siteNav) return;
|
||||
const animateAction = siteNav.classList.contains('site-nav-on') ? 'slideUp' : 'slideDown';
|
||||
|
||||
if (typeof Velocity === 'function') {
|
||||
Velocity(siteNav, animateAction, {
|
||||
duration: 200,
|
||||
complete: function() {
|
||||
siteNav.classList.toggle('site-nav-on');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
siteNav.classList.toggle('site-nav-on');
|
||||
}
|
||||
const animateAction = siteNav.classList.contains('site-nav-on');
|
||||
const height = NexT.utils.getComputedStyle(siteNav);
|
||||
siteNav.style.height = animateAction ? height : 0;
|
||||
const toggle = () => siteNav.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
|
||||
}));
|
||||
});
|
||||
|
||||
const TAB_ANIMATE_DURATION = 200;
|
||||
|
||||
@ -281,6 +281,17 @@ NexT.utils = {
|
||||
return isFirefoxWithPDFJS || (supportsPdfMimeType && !isIOS);
|
||||
},
|
||||
|
||||
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