diff --git a/assets/css/_common/outline/header/menu.scss b/assets/css/_common/outline/header/menu.scss index 01f4093..10d9d76 100644 --- a/assets/css/_common/outline/header/menu.scss +++ b/assets/css/_common/outline/header/menu.scss @@ -1,12 +1,26 @@ // Menu // -------------------------------------------------- -.menu { +.menu, .menu-children { margin: 0; padding: 1em 0; text-align: center; } -.menu-item { +.menu-children { + max-height: 0; + padding: 0; + overflow: hidden; + transition: max-height 1.5s ease-out; +} + + .menu-children { + &.expand { + max-height: 400px; + transition: max-height 1.5s ease-in; + } +} + +.menu-item, .menu-child-item { display: inline-block; list-style: none; margin: 0 10px; @@ -51,6 +65,15 @@ margin-left: 0; } } + + .menu-item-shrink-icon { + float: right; + } +} + +.menu-child-item { + display: block; + margin: 0; } .use-motion .menu-item { diff --git a/assets/css/_schemes/Pisces/_menu.scss b/assets/css/_schemes/Pisces/_menu.scss index abacc7b..f932316 100644 --- a/assets/css/_schemes/Pisces/_menu.scss +++ b/assets/css/_schemes/Pisces/_menu.scss @@ -43,4 +43,4 @@ top: 50%; width: 6px; } -} +} \ No newline at end of file diff --git a/assets/js/next-boot.js b/assets/js/next-boot.js index 47339f6..03eeedd 100644 --- a/assets/js/next-boot.js +++ b/assets/js/next-boot.js @@ -17,6 +17,7 @@ NexT.boot.registerEvents = function() { + NexT.utils.registerMenuClick(); NexT.utils.registerImageLoadEvent(); NexT.utils.registerScrollPercent(); // NexT.utils.registerCanIUseTag(); diff --git a/assets/js/utils.js b/assets/js/utils.js index e78675e..f03bf25 100644 --- a/assets/js/utils.js +++ b/assets/js/utils.js @@ -7,6 +7,29 @@ HTMLElement.prototype.wrap = function (wrapper) { }; NexT.utils = { + registerMenuClick: function() { + const pMenus = document.querySelectorAll('.main-menu > li > a.menus-parent'); + pMenus.forEach(function(item) { + const icon = item.querySelector('span > i'); + var ul = item.nextElementSibling; + + item.addEventListener('click', function(e) { + e.preventDefault(); + + ul.classList.toggle('expand'); + if (ul.classList.contains('expand')) { + icon.className = 'fa fa-angle-down'; + } else { + icon.className = 'fa fa-angle-right'; + } + }); + + var cCls = ul.querySelectorAll('.menu-item-active'); + if (cCls != null && cCls.length > 0) { + item.click(); + } + }); + }, registerImageLoadEvent: function() { const images = document.querySelectorAll('.sidebar img, .post-block img, .vendors-list img'); diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index e15c471..0074bb3 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -135,20 +135,40 @@ menus: pre: user weight: 2 - identifier: flinks - name: 站点示例 + name: 友情链接 pageref: /flinks.html pre: thumbs-up weight: 3 + - identifier: example + name: 语法示例 + pre: angles-down + weight: 4 + - identifier: flow-charts + name: 流程图 + pageref: /post/mermaid-charts.html + weight: 1 + parent: example + - identifier: math + name: 数学公式 + pageref: /post/math-formula.html + weight: 2 + parent: example + parent: example + - identifier: syntax + name: 语法高亮 + pageref: /post/syntax-highlighting.html + weight: 3 + parent: example - identifier: archives name: 归档 pageref: /archives pre: archive - weight: 4 + weight: 5 - identifier: commonweal name: 公益 404 url: /404.html pre: heartbeat - weight: 5 + weight: 6 #----------------------------------------- # Hugo NexT 主题参数配置 diff --git a/layouts/partials/header/menus.html b/layouts/partials/header/menus.html index 5e12b28..9dd2eaf 100644 --- a/layouts/partials/header/menus.html +++ b/layouts/partials/header/menus.html @@ -1,18 +1,31 @@ {{ $ms := .Site.Params.menuSets }} {{ $curP := .Page }}