提示

本文为使用butterfly博客时魔改所写;其他用途仅做参考

预览

来源

在逛博客的过程中,发现几个小伙伴的标签\分类页面都有一个导航条,可以在标签\分类页面直接跳转到其他标签\分类

比如: HEO Eurkon

思路

魔改

结构与事件

block content
  if theme.category_ui == 'index'
    include ./includes/mixins/post-ui.pug
    #recent-posts.recent-posts.category_ui
      +postUI
      include includes/pagination.pug
  else
    include ./includes/mixins/article-sort.pug
    #category
+      .category-list-bar
+        a.iconfont.icon-fenlei(href="/categories/")
+        .lists!=list_categories()
+        script.
+          document.querySelectorAll('.category-list .category-list-item').forEach(item=>{
+          if(decodeURI(window.location.href.split('/')[4])===item.querySelector('a').innerHTML){
+          item.className += ' checked'
+          }
+          })
+          window.addEventListener('load',function(){document.querySelector('.category-list .category-list-item.checked').scrollIntoView();document.querySelector('#category').scrollIntoView();});
+          document.querySelectorAll('#category .lists')[0].onmousewheel = function(e){
+          if(e.deltaY>0){
+          this.scrollLeft+=20;
+          }else{
+          this.scrollLeft-=20;
+          }return false;}
      .article-sort-title= _p('page.category') + ' - ' + page.category
      +articleSort(page.posts)
      include includes/pagination.pug

extends includes/layout.pug

block content
  if theme.tag_ui == 'index'
    include ./includes/mixins/post-ui.pug
    #recent-posts.recent-posts
      +postUI
      include includes/pagination.pug
  else
    include ./includes/mixins/article-sort.pug
+    #tag
+      .tag-list-bar
+        a.iconfont.icon-biaoqian(href="/tags/")
+        .lists
+          ul!=cloudTags({source: site.tags, minfontsize: 1, maxfontsize: 1, limit: 0, unit: 'rem'})
+        script.
+          document.querySelectorAll('#tag .lists a').forEach(item=>{
+          if(decodeURI(window.location.href.split('/')[4])===item.innerHTML){
+          item.className += 'checked';
+          }
+          })
+          window.addEventListener('load',function(){document.querySelector('.lists a.checked').scrollIntoView();document.querySelector('#tag').scrollIntoView();});
+          document.querySelectorAll('#tag .lists')[0].onmousewheel = function(e){
+          if(e.deltaY>0){
+          this.scrollLeft+=20;
+          }else{
+          this.scrollLeft-=20;
+          }return false;}
      .article-sort-title= _p('page.tag') + ' - ' + page.tag
      +articleSort(page.posts)
      include includes/pagination.pug

样式参考

/*单个分类*/
.page #category .category-list-bar,
#tag .tag-list-bar{
	width: 100%;
	height: 3rem;
	background-color: var(--kk-card-bg);
	border-radius: 0.5rem;
	line-height: 3rem;
	display: flex;
}
.page #category .category-list-bar .iconfont,
#tag .tag-list-bar .iconfont{
	width: 3rem;
	height: 3rem;
	text-align: center;
	font-size: 1.25rem;
}
.page #category .category-list-bar .lists,
#tag .tag-list-bar .lists{
	width: calc(100% - 3rem);
	overflow: scroll;
}
.page #category .category-list-bar .lists::-webkit-scrollbar,
#tag .tag-list-bar .lists::-webkit-scrollbar{
	width: 0;
	height: 0;
}
.page #category .category-list-bar .lists ul,
#tag .tag-list-bar .lists ul{
	width: max-content;
	height: 3rem;
	display: flex;
	align-items: center;
}
.page #category .category-list-bar .lists .category-list .category-list-item,
#tag .tag-list-bar .lists ul a{
	padding: 0 0.4rem;
	margin: 0 0.3rem;
	height: 2rem;
	line-height: 2rem;
	/*background: #fff;*/
	border-radius: 0.4rem;
	transition: 0.2s;
}
.page #category .category-list-bar .lists .category-list .category-list-item:hover,
.page #category .category-list-bar .lists .category-list .category-list-item.checked,
#tag .tag-list-bar .lists ul a:hover,
#tag .tag-list-bar .lists ul a.checked{
	background-color: var(--kk-border-white);
}

.page #category .category-list-bar .lists .category-list .category-list-item span{
	display: none;
}
DORAKIKA
我是一个喜欢折腾的前端工程师,对一切新鲜事物充满好奇,希望我的文章能给你带来思考和帮助
👋我是DORAKIKA
分享作者『DORAKIKA』发表的文章『给分类与标签页面添加导航栏』https://blog.dorakika.cn/post/20220313/
© 请您在需要时著名本文内容来源信息,若在文末注明“参考、扩展”等字样涉及转载第三方内容,请您一同复制
自定义右键菜单
自定义右键菜单
为博客添加一个右键菜单