mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-17 18:22:33 +00:00
Make the nav bar of tabs stick to the top (#361)
This commit is contained in:
parent
76bba71574
commit
61048546ca
@ -796,6 +796,8 @@ note:
|
|||||||
|
|
||||||
# Tabs tag
|
# Tabs tag
|
||||||
tabs:
|
tabs:
|
||||||
|
# Make the nav bar of tabs with long content stick to the top.
|
||||||
|
sticky: false
|
||||||
transition:
|
transition:
|
||||||
tabs: false
|
tabs: false
|
||||||
labels: true
|
labels: true
|
||||||
|
|||||||
@ -23,6 +23,7 @@ hexo.extend.helper.register('next_config', function() {
|
|||||||
lazyload : theme.lazyload,
|
lazyload : theme.lazyload,
|
||||||
pangu : theme.pangu,
|
pangu : theme.pangu,
|
||||||
comments : theme.comments,
|
comments : theme.comments,
|
||||||
|
stickytabs: theme.tabs.sticky,
|
||||||
motion : theme.motion,
|
motion : theme.motion,
|
||||||
prism : config.prismjs.enable && !config.prismjs.preprocess,
|
prism : config.prismjs.enable && !config.prismjs.preprocess,
|
||||||
i18n : {
|
i18n : {
|
||||||
|
|||||||
@ -6,10 +6,14 @@
|
|||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
|
|
||||||
ul.nav-tabs {
|
ul.nav-tabs {
|
||||||
|
background: (($scheme == 'Muse') or ($scheme == 'Mist')) ? var(--body-bg-color) : var(--content-bg-color);
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
position: -webkit-sticky;
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
|
||||||
+mobile-smallest() {
|
+mobile-smallest() {
|
||||||
display: block;
|
display: block;
|
||||||
|
|||||||
@ -176,8 +176,9 @@ NexT.utils = {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
// Prevent selected tab to select again.
|
// Prevent selected tab to select again.
|
||||||
if (element.classList.contains('active')) return;
|
if (element.classList.contains('active')) return;
|
||||||
|
const nav = element.parentNode;
|
||||||
// Add & Remove active class on `nav-tabs` & `tab-content`.
|
// Add & Remove active class on `nav-tabs` & `tab-content`.
|
||||||
[...element.parentNode.children].forEach(target => {
|
[...nav.children].forEach(target => {
|
||||||
target.classList.toggle('active', target === element);
|
target.classList.toggle('active', target === element);
|
||||||
});
|
});
|
||||||
// https://stackoverflow.com/questions/20306204/using-queryselector-with-ids-that-are-numbers
|
// https://stackoverflow.com/questions/20306204/using-queryselector-with-ids-that-are-numbers
|
||||||
@ -189,6 +190,14 @@ NexT.utils = {
|
|||||||
tActive.dispatchEvent(new Event('tabs:click', {
|
tActive.dispatchEvent(new Event('tabs:click', {
|
||||||
bubbles: true
|
bubbles: true
|
||||||
}));
|
}));
|
||||||
|
if (!CONFIG.stickytabs) return;
|
||||||
|
const offset = nav.parentNode.getBoundingClientRect().top + window.scrollY + 10;
|
||||||
|
window.anime({
|
||||||
|
targets : document.scrollingElement,
|
||||||
|
duration : 500,
|
||||||
|
easing : 'linear',
|
||||||
|
scrollTop: offset
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user