mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-21 19:32:34 +00:00
Refactor sidebar motion
This commit is contained in:
parent
e57bf4558c
commit
45d6e0413d
@ -13,11 +13,11 @@
|
|||||||
top: 0;
|
top: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
z-index: $zindex-1;
|
z-index: $zindex-1;
|
||||||
}
|
|
||||||
|
|
||||||
.sidebar-active + #sidebar-dimmer {
|
.sidebar-active & {
|
||||||
opacity: .7;
|
opacity: .7;
|
||||||
transform: translateX(-100%);
|
transform: translateX(-100%);
|
||||||
transition: opacity .5s;
|
transition: opacity .5s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,12 +13,7 @@ body {
|
|||||||
font-family: $font-family-base;
|
font-family: $font-family-base;
|
||||||
font-size: $font-size-base;
|
font-size: $font-size-base;
|
||||||
line-height: $line-height-base;
|
line-height: $line-height-base;
|
||||||
|
the-transition();
|
||||||
+tablet-mobile() {
|
|
||||||
// Remove the padding of body when the sidebar is open.
|
|
||||||
padding-left: 0 !important;
|
|
||||||
padding-right: 0 !important;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h1, h2, h3, h4, h5, h6 {
|
h1, h2, h3, h4, h5, h6 {
|
||||||
|
|||||||
@ -1,8 +1,14 @@
|
|||||||
if (hexo-config('sidebar.position') == 'right') {
|
if (hexo-config('sidebar.position') == 'right') {
|
||||||
|
.sidebar-active {
|
||||||
|
+desktop() {
|
||||||
|
padding-right: $sidebar-desktop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.sidebar {
|
.sidebar {
|
||||||
right: 0 - $sidebar-desktop;
|
right: 0 - $sidebar-desktop;
|
||||||
|
|
||||||
&.sidebar-active {
|
.sidebar-active & {
|
||||||
right: 0;
|
right: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -20,10 +26,16 @@ if (hexo-config('sidebar.position') == 'right') {
|
|||||||
left: $b2t-position-right;
|
left: $b2t-position-right;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
.sidebar-active {
|
||||||
|
+desktop() {
|
||||||
|
padding-left: $sidebar-desktop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.sidebar {
|
.sidebar {
|
||||||
left: 0 - $sidebar-desktop;
|
left: 0 - $sidebar-desktop;
|
||||||
|
|
||||||
&.sidebar-active {
|
.sidebar-active & {
|
||||||
left: 0;
|
left: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
/* global NexT, CONFIG, Velocity */
|
/* global CONFIG, Velocity */
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
|
||||||
const isRight = CONFIG.sidebar.position === 'right';
|
const isRight = CONFIG.sidebar.position === 'right';
|
||||||
const SIDEBAR_WIDTH = CONFIG.sidebar.width || 320;
|
|
||||||
const SIDEBAR_DISPLAY_DURATION = 200;
|
|
||||||
const mousePos = {};
|
const mousePos = {};
|
||||||
|
|
||||||
const sidebarToggleLines = {
|
const sidebarToggleLines = {
|
||||||
@ -23,7 +21,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const sidebarToggleMotion = {
|
const sidebarToggleMotion = {
|
||||||
sidebarEl : document.querySelector('.sidebar'),
|
|
||||||
isSidebarVisible: false,
|
isSidebarVisible: false,
|
||||||
init : function() {
|
init : function() {
|
||||||
sidebarToggleLines.init();
|
sidebarToggleLines.init();
|
||||||
@ -64,7 +61,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
},
|
},
|
||||||
showSidebar: function() {
|
showSidebar: function() {
|
||||||
this.isSidebarVisible = true;
|
this.isSidebarVisible = true;
|
||||||
this.sidebarEl.classList.add('sidebar-active');
|
document.body.classList.add('sidebar-active');
|
||||||
if (typeof Velocity === 'function') {
|
if (typeof Velocity === 'function') {
|
||||||
Velocity(document.querySelectorAll('.sidebar .motion-element'), isRight ? 'transition.slideRightIn' : 'transition.slideLeftIn', {
|
Velocity(document.querySelectorAll('.sidebar .motion-element'), isRight ? 'transition.slideRightIn' : 'transition.slideLeftIn', {
|
||||||
stagger: 50,
|
stagger: 50,
|
||||||
@ -73,30 +70,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sidebarToggleLines.close();
|
sidebarToggleLines.close();
|
||||||
NexT.utils.isDesktop() && window.anime(Object.assign({
|
|
||||||
targets : document.body,
|
|
||||||
duration: SIDEBAR_DISPLAY_DURATION,
|
|
||||||
easing : 'linear'
|
|
||||||
}, isRight ? {
|
|
||||||
'padding-right': SIDEBAR_WIDTH
|
|
||||||
} : {
|
|
||||||
'padding-left': SIDEBAR_WIDTH
|
|
||||||
}));
|
|
||||||
},
|
},
|
||||||
hideSidebar: function() {
|
hideSidebar: function() {
|
||||||
this.isSidebarVisible = false;
|
this.isSidebarVisible = false;
|
||||||
this.sidebarEl.classList.remove('sidebar-active');
|
document.body.classList.remove('sidebar-active');
|
||||||
|
|
||||||
sidebarToggleLines.init();
|
sidebarToggleLines.init();
|
||||||
NexT.utils.isDesktop() && window.anime(Object.assign({
|
|
||||||
targets : document.body,
|
|
||||||
duration: SIDEBAR_DISPLAY_DURATION,
|
|
||||||
easing : 'linear'
|
|
||||||
}, isRight ? {
|
|
||||||
'padding-right': 0
|
|
||||||
} : {
|
|
||||||
'padding-left': 0
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
sidebarToggleMotion.init();
|
sidebarToggleMotion.init();
|
||||||
|
|||||||
@ -312,24 +312,6 @@ NexT.utils = {
|
|||||||
createIntersectionObserver(document.documentElement.scrollHeight);
|
createIntersectionObserver(document.documentElement.scrollHeight);
|
||||||
},
|
},
|
||||||
|
|
||||||
hasMobileUA: function() {
|
|
||||||
let ua = navigator.userAgent;
|
|
||||||
let pa = /iPad|iPhone|Android|Opera Mini|BlackBerry|webOS|UCWEB|Blazer|PSP|IEMobile|Symbian/g;
|
|
||||||
return pa.test(ua);
|
|
||||||
},
|
|
||||||
|
|
||||||
isTablet: function() {
|
|
||||||
return window.screen.width < 992 && window.screen.width > 767 && this.hasMobileUA();
|
|
||||||
},
|
|
||||||
|
|
||||||
isMobile: function() {
|
|
||||||
return window.screen.width < 767 && this.hasMobileUA();
|
|
||||||
},
|
|
||||||
|
|
||||||
isDesktop: function() {
|
|
||||||
return !this.isTablet() && !this.isMobile();
|
|
||||||
},
|
|
||||||
|
|
||||||
supportsPDFs: function() {
|
supportsPDFs: function() {
|
||||||
let ua = navigator.userAgent;
|
let ua = navigator.userAgent;
|
||||||
let isFirefoxWithPDFJS = ua.includes('irefox') && parseInt(ua.split('rv:')[1].split('.')[0], 10) > 18;
|
let isFirefoxWithPDFJS = ua.includes('irefox') && parseInt(ua.split('rv:')[1].split('.')[0], 10) > 18;
|
||||||
@ -369,7 +351,7 @@ NexT.utils = {
|
|||||||
document.querySelector('.sidebar-nav-overview').click();
|
document.querySelector('.sidebar-nav-overview').click();
|
||||||
}
|
}
|
||||||
NexT.utils.initSidebarDimension();
|
NexT.utils.initSidebarDimension();
|
||||||
if (!this.isDesktop() || CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') return;
|
if (window.screen.width < 992 || CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') return;
|
||||||
// Expand sidebar on post detail page by default, when post has a toc.
|
// Expand sidebar on post detail page by default, when post has a toc.
|
||||||
let display = CONFIG.page.sidebar;
|
let display = CONFIG.page.sidebar;
|
||||||
if (typeof display !== 'boolean') {
|
if (typeof display !== 'boolean') {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user