导航栏美化
文章摘要
HrnAI
文章摘要初始化中...
Butterfly主题导航栏美化
介绍作者 JayHrn
生成本文简介
推荐相关文章
前往主页
看看其他文章
此内容由作者归纳总结,仅用于文章内容的解释与总结,如有不当之处,请予指正!
反馈看到了那么多好看的导航栏,感觉Heo的非常的好看,一开始想直接f12取到,但是发现怎么都实现不了,甚至导航栏直接寄了(应该是f12的技能有待提示吧)。没办法,后来也发现了类似的导航栏,借鉴了Eurkon的博客,两者十分的接近,并且实现了。
刚好最近有人问导航栏怎么实现的,那么就开始吧!
教程
修改
themes/butterfly/layout/includes/header/nav.pug
,直接全部覆盖1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30nav#nav
#nav-group
span#blog_name
a#site-name(href="/" title="返回博客主页")
span JAYHRN
span#page_name
a#page-name-text(title=_p("rightside.back_to_top") onclick="btf.scrollToDest(0,500)")
span #[=config.title]
#menus
!=partial('includes/header/menu_item', {}, {cache: true})
#hotkey
if (theme.algolia_search.enable || theme.local_search.enable)
#search-button
a.site-page.social-icon.search(title=_p('search.title'))
i.ri-search-eye-line
#randompost-button
a.site-page(title="随机文章" onclick="toRandomPost()")
i.ri-subway-fill
if (theme.darkmode.enable && theme.darkmode.button)
#mode-button
a.site-page(title=_p('rightside.night_mode_title') onclick="switchDarkMode()")
i.ri-sun-fill
#top-button
a.site-page(title=_p("rightside.back_to_top") onclick="btf.scrollToDest(0,500)")
i.ri-plane-fill
#toggle-menu
a.site-page
i.fas.fa-bars.fa-fw引入导航栏图标,也可以自行换成其他的图标
1
2
3
4inject:
head:
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Jayhrn/fontawesome-pro/css/all.min.css">
- <link rel="stylesheet" href="https://npm.elemecdn.com/remixicon@2.5.0/fonts/remixicon.css">自定义
css
文件并引入1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
#nav #nav-group {
max-width: 1376px;
justify-content: center
}
.layout {
max-width: 1400px;
justify-content: center
}
@media screen and (min-width: 1920px) {
.layout.hide-aside {
max-width: 1600px
}
#nav #nav-group, .layout {
max-width: 1500px
}
}
#nav {
top: 0 ;
display: flex;
justify-content: center;
box-shadow: none ;
-webkit-box-shadow: none ;
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
transition: all .3s ease-in-out
}
#nav #nav-group {
width: 100%;
display: flex;
position: relative
}
#nav .site-page::after {
display: none
}
#nav .site-page {
text-shadow: none;
border-radius: 8px;
}
.page .sticky_layout {
top: 50px
}
#post ~ .aside-content .sticky_layout {
top: 70px
}
#nav.show {
-webkit-transform: translate3d(0, 0, 0) ;
-moz-transform: translate3d(0, 0, 0) ;
-o-transform: translate3d(0, 0, 0) ;
-ms-transform: translate3d(0, 0, 0) ;
transform: translate3d(0, 0, 0) ;
position: fixed;
z-index: 91
}
#page-header.nav-fixed #nav.show, #page-header.not-top-img #nav.show {
border-bottom: none
}
#page-header.not-top-img:not(.nav-fixed) #nav {
background: var(--Jay-background)
}
#page-header.not-top-img #nav {
transition: .3s;
background: var(--Jay-maskbgdeep) ;
backdrop-filter: saturate(180%) blur(20px);
-webkit-backdrop-filter: blur(20px);
}
@media screen and (max-width: 768px) {
#page-header.not-top-img #nav {
background: var(--Jay-background)
}
}
#nav a {
border-radius: 8px;
padding: 6px 12px ;
}
@media screen and (min-width: 768px) {
.menus_item:hover > a.site-page {
color: var(--Jay-white) ;
background: var(--Jay-white-op);
transition: .3s;
box-shadow: var(--Jay-shadow-main)
}
.page .menus_item:hover > a.site-page {
color: var(--Jay-white) ;
background: var(--Jay-main);
transition: .3s;
box-shadow: var(--Jay-shadow-main)
}
.nav-fixed .menus_item:hover > a.site-page {
background-color: var(--Jay-main)
}
}
.nav-fixed #nav #site-name span {
color: var(--Jay-fontcolor);
transition: .3s
}
#nav #site-name:hover i {
color: var(--Jay-white)
}
#nav #menus {
position: absolute;
width: 100%;
}
#nav #site-name span {
font-weight: 700 ;
font-size: 1.1rem;
}
@media screen and (min-width: 900px) {
#nav #site-name {
opacity: 1;
transition: .3s;
overflow: hidden
}
#nav #site-name span {
transition: .3s
}
#nav #site-name:hover span {
opacity: 0;
transition: .3s
}
#page-header.nav-fixed #nav #site-name {
opacity: 1;
transition: .1s
}
#page-header.nav-visible #nav #site-name {
opacity: 1;
transition: .1s
}
#nav #site-name:after {
background: url('https://cdn.jsdelivr.net/gh/Jayhrn/CDN/img/home.png') no-repeat 50% 50%;
opacity: 0;
position: absolute;
display: flex;
z-index: 1;
width: 80px;
height: 60px;
content: "";
transition: .3s;
transition-timing-function: ease-in;
transform: scale(.4)
}
.post #nav #site-name:hover {
background: var(--Jay-white-op)
}
.nav-fixed #nav #site-name:hover {
background: var(--Jay-main)
}
#nav #site-name:hover:after {
opacity: 1;
transform: translateY(0) scale(.3);
transition-timing-function: ease-in
}
}
.nav-fixed #nav #site-name span {
color: var(--Jay-fontcolor);
transition: .3s
}
#nav #site-name:hover span {
color: var(--Jay-white)
}
.post-bg #nav #site-name {
color: var(--Jay-white);
transition: .3s
}
#nav #site-name {
color: var(--Jay-white);
padding: 0;
transition: .3s;
display: flex;
height: 40px;
width: 80px;
justify-content: center;
align-items: center;
text-shadow: none
}
#nav #blog_name #site-name {
position: relative
}
/*设置menu子元素边距*/
#nav .menus_item_child .site-page.child {
padding: .5rem .8rem
}
#nav #menus {
position: absolute;
width: 100%
}
@media screen and (max-width: 768px) {
#nav #menus {
display: none
}
}
#nav .menus_items {
display: inline;
position: absolute;
text-align: center;
width: fit-content;
left: 0;
right: 0;
margin: auto
}
#menus > div.menus_items > div > a {
letter-spacing: .2rem;
font-size: 1.1rem;
}
#page-header.nav-fixed #nav div.menus_items[style*="opacity: 0;"] .nav {
opacity: .3;
}
#page-header.nav-fixed #nav div.menus_items {
opacity: 0;
-webkit-transform: translateY(-60px);
-moz-transform: translateY(-60px);
-o-transform: translateY(-60px);
-ms-transform: translateY(-60px);
transform: translateY(-60px);
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
transition: all .3s ease-in-out
}
#page-header.nav-fixed.nav-visible #nav div.menus_items {
opacity: 1;
-webkit-transform: translateY(0);
-moz-transform: translateY(0);
-o-transform: translateY(0);
-ms-transform: translateY(0);
transform: translateY(0);
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
transition: all .3s ease-in-out
}
#nav .menus_items .menus_item {
padding: 0 .4rem
}
#nav .menus_items .menus_item .menus_item_child {
padding: 6px 4px 8px 4px;
background-color: var(--Jay-card-bg);
border-radius: 12px;
border: var(--style-border);
box-shadow: var(--Jay-shadow-black);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
transition: all .3s ease-in-out
}
#nav .menus_items .menus_item .menus_item_child:hover {
border: var(--style-border-hover);
box-shadow: var(--Jay-shadow-main)
}
#nav .menus_items .menus_item:hover .menus_item_child {
display: flex
}
#nav .menus_items .menus_item .menus_item_child li {
margin: 0 .2rem;
border-radius: 8px ;
}
#nav .menus_items .menus_item .menus_item_child li:hover {
background: 0 0;
background: var(--Jay-main) ;
color: var(--Jay-white) ;
box-shadow: var(--Jay-shadow-main);
transform: scale(1) ;
transition: .3s;
border-radius: 8px ;
}
#sidebar #sidebar-menus .menus_items .site-page:hover, #sidebar #sidebar-menus .sidebar-site-data a:hover {
border-radius: 8px;
background: var(--Jay-main);
color: var(--Jay-white) ;
}
/*设置电脑无向下箭头,而手机有*/
@media screen and (max-width: 768px) {
.site-page i.fa-chevron-down {
display: inline-flex ;
}
}
.site-page i.fa-chevron-down {
display: none;
}
#sidebar #sidebar-menus .menus_items .site-page:hover, #sidebar #sidebar-menus .sidebar-site-data a:hover .headline, #sidebar #sidebar-menus .sidebar-site-data a:hover .length-num {
color: var(--Jay-white)
}
#page-header.not-top-img {
margin: 0
}
#nav a.site-page.child {
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
transition: all .3s ease-in-out
}
#nav a.site-page.child:hover {
color: var(--Jay-main) ;
background: var(--Jay-main);
box-shadow: var(--Jay-shadow-main)
}
#page-header.post-bg #nav #hotkey .site-page:hover, #page-header.post-bg #nav #site-name:hover, #page-header.post-bg #nav .menus_item > .site-page:hover {
color: var(--Jay-white) ;
background: var(--Jay-main);
}
[data-theme=dark] #page-header.post-bg #nav #hotkey .site-page:hover, [data-theme=dark] #page-header.post-bg #nav #site-name:hover, [data-theme=dark] #page-header.post-bg #nav .menus_item > .site-page:hover {
color: var(--Jay-white) ;
background: var(--Jay-main)
}
#page-header.post-bg #nav #hotkey .site-page, #page-header.post-bg #nav #site-name, #page-header.post-bg #nav .menus_item > .site-page {
color: var(--Jay-white);
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
transition: all .3s ease-in-out
}
#page-header.not-top-img #nav #hotkey .site-page, #page-header.not-top-img #nav #page-name-text, #page-header.not-top-img #nav #site-name, #page-header.not-top-img #nav .menus_item > .site-page, #page-header.post-bg.nav-fixed #nav #hotkey .site-page, #page-header.post-bg.nav-fixed #nav #page-name-text, #page-header.post-bg.nav-fixed #nav #site-name, #page-header.post-bg.nav-fixed #nav .menus_item > .site-page {
color: var(--Jay-fontcolor);
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
transition: all .3s ease-in-out
}
#page-header.not-top-img #nav #hotkey .site-page:hover, #page-header.not-top-img #nav #page-name-text:hover, #page-header.not-top-img #nav #site-name:hover, #page-header.not-top-img #nav .menus_item > .site-page:hover, #page-header.post-bg.nav-fixed #nav #hotkey .site-page:hover, #page-header.post-bg.nav-fixed #nav #page-name-text:hover, #page-header.post-bg.nav-fixed #nav #site-name:hover, #page-header.post-bg.nav-fixed #nav .menus_item > .site-page:hover {
color: var(--Jay-white) ;
background: var(--Jay-main);
box-shadow: var(--Jay-shadow-main);
}
#nav #page_name {
position: absolute
}
@media screen and (max-width: 768px) {
#nav #page_name {
display: none
}
}
#nav #page-name-text {
opacity: 0;
font-weight: 700;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
position: relative;
text-align: center;
line-height: 1.2em;
-webkit-transform: translateY(-60px);
-moz-transform: translateY(-60px);
-o-transform: translateY(-60px);
-ms-transform: translateY(-60px);
transform: translateY(-50px);
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
transition: all .3s ease-in-out
}
#page-header.nav-fixed #nav #page-name-text {
opacity: 1;
-webkit-transform: translateY(0);
-moz-transform: translateY(0);
-o-transform: translateY(0);
-ms-transform: translateY(0);
transform: translateY(0)
}
#page-header.nav-fixed.nav-visible #nav #page-name-text {
opacity: 0;
-webkit-transform: translateY(-60px);
-moz-transform: translateY(-60px);
-o-transform: translateY(-60px);
-ms-transform: translateY(-60px);
transform: translateY(-60px)
}
/* 设置hover返回顶部 */
#page-name-text > span::before {
font-size: 1.2rem;
position: absolute;
width: 100%;
height: 100%;
border-radius: 8px;
color: var(--Jay-white) ;
top: 0;
left: 0;
content: '回到顶部';
min-width: fit-content;
background-color: var(--Jay-theme);
transition: all .3s;
-webkit-transition: all .3s;
-moz-transition: all .3s;
-ms-transition: all .3s;
-o-transition: all .3s;
opacity: 0;
box-shadow: 0 0 3px var(--Jay-theme);
line-height: 40px; /*如果垂直位置不居中可以微调此值,也可以删了*/
}
#page-name-text > span:hover:before {
opacity: 1;
}
#page-name-text:hover {
scale: 1.03
}
#nav #hotkey {
position: absolute;
right: 1rem;
display: flex;
flex-direction: row;
height: 100%;
align-items: center;
text-align: center
}
#nav #hotkey div {
width: 40px;
height: 40px;
margin-left: .3rem;
padding: 0 ;
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
transition: all .3s ease-in-out
}
#nav #hotkey .site-page {
width: 40px;
height: 40px;
font-size: 1.3rem;
padding: 0 ;
position: absolute;
top: 50%;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-o-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%)
}
#nav #hotkey #mode-button i {
color: var(--Jay-sun-moon)
}
#nav #hotkey #mode-button i::before {
content: '\f1bc'
}
#nav #hotkey #mode-button:hover i::before {
content: '\ef6e'
}
[data-theme=dark] #nav #hotkey #mode-button i::before {
content: '\ef6e'
}
[data-theme=dark] #nav #hotkey #mode-button:hover i::before {
content: '\f1bc'
}
/* 控制导航栏滑动百分比显隐 */
header:not(.nav-fixed) #nav #hotkey #top-button {
width: 0;
opacity: 0;
margin-left: 0
}
#nav #hotkey #top-button a.site-page {
width: 30px;
height: 30px;
margin: 0 5px;
color: var(--font-color) ;
background: var(--Jay-card-bg)
}
#nav #hotkey #top-button:hover a.site-page {
width: 40px;
height: 40px;
margin: 0;
color: var(--Jay-secondtext) ;
background: var(--Jay-main)
}
#nav #hotkey #top-button i::before {
content: attr(data-percent);
position: absolute;
left: 0;
right: 0;
font-size: 90%;
line-height: 1.7em;
white-space: nowrap;
font-family: Jay
}
#nav #hotkey #top-button:hover i::before {
content: '\f004';
position: relative;
font-family: unset;
font-size: 100%
}引入js,实现获取主页标题或文章标题,引入到自定义
js
文件中,没有可以新建themes/butterfly/source/js/custom/custom.js
文件1
"" === GLOBAL_CONFIG_SITE.title.replace("JayHrn", "") ? document.getElementById("page-name-text").style.display = "none" : document.querySelector("#page-name-text>span").innerHTML = document.title.split(" | Jayhrn")[0];
其中
JayHrn
换成自己的网站名称设置网页阅读进度,下方引入自定义
js
文件,没有可以新建themes/butterfly/source/js/custom/custom.js
文件1
2
3
4
5
6var $percent = document.querySelector("#nav #hotkey #top-button a.site-page i");
$percent && window.addEventListener("scroll", (function () {
let e = document.body.scrollHeight || document.documentElement.scrollHeight,
t = window.innerHeight || document.documentElement.clientHeight;
$percent.dataset.percent = ((document.body.scrollTop || document.documentElement.scrollTop) / (e - t) * 100).toFixed(0)
}));
关于随机页面跳转,可以参考本博客的Hexo博客实现页面随机跳转,自由选择其中一种即可。
至此,你就可以看到和我一样的效果啦。
- 感谢你赐予我前进的力量
赞赏者名单
因为你们的支持让我意识到写文章的价值🙏
本文是原创文章,采用CC BY-NC-SA 4.0协议,完整转载请注明来自JayHrn
评论
匿名评论
隐私政策
✅ 你无需删除空行,直接评论以获取最佳展示效果