butterfly折腾(三)主题魔改
通过挂载 CSS、JS 或者修改主题源来实现更多功能,折腾就完事了
魔改说明
主要通过挂载 CSS、JS 的方法魔改,尽可能少地修改主题源码,给升级造成困难
butterfly主题挂载 CSS、JS 方法:
打开主题配置文件,搜索inject:
,在对应位置挂载css
或者js
文件即可。这是 buterfly 主题特有的挂载方法,十分方便
- 在
themes/butterfly/source/css/
目录下创建一个custom.css
文件(可自定义名称),里面填写 CSS 代码;
在themes/butterfly/source/js/
目录下创建一个custom.js
文件(可自定义名称),里面填写 js 代码。js 文件访问异常容易造成阻塞,所以尽可能少用。 - 修改
主题配置文件
1
2
3
4
5inject:
head: # 挂载 css
- <link rel="stylesheet" href="/css/custom.css">
bottom: # 挂载 js
- <script src="/js/custom.js"></script>
布局修改
导航栏居中
1 | /*导航栏居中*/ |
首页横向双栏布局
- 修改主题配置文件
1
2
3
4cover:
# the position of cover in home page (封面顯示的位置)
# left/right/both
position: left - 修改样式
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/*首页文章双栏布局*/
@media screen and (min-width: 1300px) {
#recent-posts {
margin-top: -1.25rem;/*第一排间距调整,若有磁贴或日历请注释掉该行*/
align-content: flex-start;
display: flex;
flex-wrap: wrap;/*规定灵活的项目在必要的时候拆行或拆列。*/
justify-content: space-between;
width: 80%;
}
#recent-posts>.recent-post-item {
margin-top: 1.25rem;/*左边第一列间距调整*/
display: flex;
flex-direction: row;
height: 15em;/*文章容器容器高度*/
width: 49.5%;/*文章容器容器宽度*/
}
#recent-posts>.recent-post-item .post_cover {
width: 40%;/*图片封面宽度*/
height: 100%;/*图片封面高度*/
}
#recent-posts>.recent-post-item .post_cover img.post_bg {
width: 100%;/*图片宽度*/
height: 100%;/*图片高度*/
}
#recent-posts>.recent-post-item .left_radius {
border-radius: 8px 8px 0 0;/*圆角修改*/
}
#recent-posts>.recent-post-item .right_radius {
border-radius: 8px 8px 0 0;/*圆角修改*/
}
.recent-post-info {
padding: 0 20px ;/*文字容器左右间距*/
margin-top: 1em;/*文字容器上间距*/
width: 60% ;/*文字容器宽度*/
}
#recent-posts>.recent-post-item>.recent-post-info>.article-meta-wrap {
margin-bottom: 1rem;/*控制标题meta信息的底部间距*/
}
/*底部页码导航居中*/
#pagination {
overflow: hidden;
margin-top: 1rem;
width: 100%;
}
/*内页容器加宽*/
.layout#content-inner {
max-width: 1450px;
}
#aside-content {
width: 20%;
padding-left: 0.8rem;/*侧边栏与首页文章容器距离*/
}
/*文章内页居中显示*/
.layout {
display: flex;
justify-content: center;
padding: .5rem 1.5rem;
}
}
标签页美化(源)
参考https://blog.leonus.cn/2022/tags.html
修改butterfly\scripts\helpers\page.js
1 | # 添加标签数量 |
标签从大到小排序
1 | hexo.extend.helper.register('cloudTags', function(options = {}) { |
加上边框
1 | /* 标签 */ |
渐变色分类页布局(源)
样式修改
将themes\butterfly\source\css\_page\categories.styl
内容全部替换即可
1 | .category-lists |
关闭分类和标签页的侧边栏
为分类和标签页添加一个侧边栏总开关,参考:Butterffly 分类页和标签页隐藏侧栏 | Eurkon
- 修改主题配置文件(默认false关闭状态,值为true时启用侧边栏)
1
2
3
4
5
6
7
8aside:
enable: true
hide: false
button: true
mobile: true # display on mobile
position: right # left or right
+ categories: false # 分类页侧栏开关
+ tags: false # 标签页侧栏开关 - 添加判断代码,修改
\themes\butterfly\layout\includes\layout.pug
1
2
3
4
5
6- var htmlClassHideAside = theme.aside.enable && theme.aside.hide ? 'hide-aside' : ''
- page.aside = is_archive() ? theme.aside.archives : page.aside // - 归档页隐藏侧栏
+ - page.aside = is_category() || page.type === 'categories' ? theme.aside.categories : page.aside // - 分类页隐藏侧栏
+ - page.aside = is_tag() || page.type === 'tags' ? theme.aside.tags : page.aside // - 标签页隐藏侧栏
- var hideAside = !theme.aside.enable || page.aside === false ? 'hide-aside' : ''
- var pageType = is_post() ? 'post' : 'page'
自用子页面布局(源)
- 使标题显示在日期上方,修改
themes\butterfly\layout\includes\mixins\article-sort.pug
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21mixin articleSort(posts)
.article-sort
- var year
- posts.each(function (article) {
- let tempYear = date(article.date, 'YYYY')
- let no_cover = article.cover === false || !theme.cover.archives_enable ? 'no-article-cover' : ''
- let title = article.title || _p('no_title')
if tempYear !== year
- year = tempYear
.article-sort-item.year= year
.article-sort-item(class=no_cover)
if article.cover && theme.cover.archives_enable
a.article-sort-item-img(href=url_for(article.path) title=title)
img(src=url_for(article.cover) alt=title onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'`)
.article-sort-item-info
+ a.article-sort-item-title(href=url_for(article.path) title=title)= title
.article-sort-item-time
i.far.fa-calendar-alt
time.post-meta-date-created(datetime=date_xml(article.date) title=_p('post.created') + ' ' + full_date(article.date))= date(article.date, config.date_format)
- a.article-sort-item-title(href=url_for(article.path) title=title)= title
- }) - 待更新
Eurkon子页面布局(源)
样式 预览,参考:Butterfly 分类标签归档页增加文章索引 | Eurkon
修改文章渲染函数
\themes\butterfly\layout\includes\mixins\article-sort.pug
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22- mixin articleSort(posts)
+ mixin articleSort(posts, current)
.article-sort
- var year
- posts.each(function (article) {
- let tempYear = date(article.date, 'YYYY')
- let no_cover = article.cover === false || !theme.cover.archives_enable ? 'no-article-cover' : ''
- let title = article.title || _p('no_title')
if tempYear !== year
- year = tempYear
.article-sort-item.year= year
.article-sort-item(class=no_cover)
if article.cover && theme.cover.archives_enable
a.article-sort-item-img(href=url_for(article.path) title=title)
img(src=url_for(article.cover) alt=title onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'`)
.article-sort-item-info
.article-sort-item-time
i.far.fa-calendar-alt
time.post-meta-date-created(datetime=date_xml(article.date) title=_p('post.created') + ' ' + full_date(article.date))= date(article.date, config.date_format)
a.article-sort-item-title(href=url_for(article.path) title=title)= title
+ span.article-sort-item-index= (current - 1) * config.per_page + post_index + 1
- })修改归档、分类、标签页面
归档页面\themes\butterfly\layout\archive.pug
1
2
3
4
5
6
7
8
9extends includes/layout.pug
block content
include ./includes/mixins/article-sort.pug
#archive
.article-sort-title= _p('page.articles') + ' - ' + site.posts.length
- +articleSort(page.posts)
+ +articleSort(page.posts, page.current)
include includes/pagination.pug分类页面
\themes\butterfly\layout\archive.pug
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15extends includes/layout.pug
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
.article-sort-title= _p('page.category') + ' - ' + page.category
- +articleSort(page.posts)
+ +articleSort(page.posts, page.current)
include includes/pagination.pug标签页面
\themes\butterfly\layout\tag.pug
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15extends 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
.article-sort-title= _p('page.tag') + ' - ' + page.tag
- +articleSort(page.posts)
+ +articleSort(page.posts, page.current)
include includes/pagination.pug修改样式
\themes\butterfly\source\css\_page\archives.styl
,大概在 100 行的位置,增加.article-sort-item-index
的样式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.article-sort
margin-left: 10px
padding-left: 20px
border-left: 2px solid lighten($light-blue, 20)
&-title
position: relative
margin-left: 10px
padding-bottom: 20px
padding-left: 20px
font-size: 1.72em
&:hover
&:before
border-color: var(--pseudo-hover)
&:before
position: absolute
top: calc(((100% - 36px) / 2))
left: -9px
z-index: 1
width: w = 10px
height: h = w
border: .5 * w solid $light-blue
border-radius: w
background: var(--card-bg)
content: ''
line-height: h
transition: all .2s ease-in-out
&:after
position: absolute
bottom: 0
left: 0
z-index: 0
width: 2px
height: 1.5em
background: lighten($light-blue, 20)
content: ''
&-item
position: relative
display: flex
align-items: center
margin: 0 0 20px 10px
transition: all .2s ease-in-out
&:hover
&:before
border-color: var(--pseudo-hover)
&:before
$w = 6px
position: absolute
left: calc(-20px - 17px)
width: w = $w
height: h = w
border: .5 * w solid $light-blue
border-radius: w
background: var(--card-bg)
content: ''
transition: all .2s ease-in-out
&.no-article-cover
height: 80px
.article-sort-item-info
padding: 0
&.year
font-size: 1.43em
&:hover
&:before
border-color: $light-blue
&:before
border-color: var(--pseudo-hover)
&-time
color: $theme-meta-color
font-size: 95%
time
padding-left: 6px
cursor: default
&-title
@extend .limit-more-line
color: var(--font-color)
font-size: 1.1em
transition: all .3s
-webkit-line-clamp: 2
&:hover
color: $text-hover
transform: translateX(10px)
+ &-index
+ opacity: .5
+ position: absolute
+ top: .5rem
+ right: .5rem
+ font-style: italic
+ font-size: 2.5rem
+ line-height: 1.5rem
&-img
overflow: hidden
width: 80px
height: 80px
img
@extend .imgHover
&-info
flex: 1
padding: 0 16px
底部页码导航(源)
底部页码导航下一页按钮靠右显示,修改theme\butterfly\source\css\_layout\pagination.styl
1 | #pagination |
底部分类导航栏(源)
修改\theme\butterfly\layout\includes\footer.pug
1 | #footer_icon |
1 | #footer { |
功能拓展
引入 iconfont 图标
通过font-class
方式引入阿里图标,默认无色,后台可开启彩色图标,单一项目内彩色图标个数上限40个
- 拷贝项目下面生成的`font-class 代码,如:
1
//at.alicdn.com/t/font_3348844_6k3vcwzq4su.css
- 修改主题配置文件
1
2
3
4
5
6inject:
head: # 挂载css
# - <link rel="stylesheet" href="/xxx.css">
- <link rel="stylesheet" href="//at.alicdn.com/t/font_3348844_6k3vcwzq4su.css">
bottom: # 挂载js
# - <script src="xxxx"></script> - 使用
1
iconfont icon-xxx
Volantis 标签移植
span
- 复制
hexo-theme-volantis/source/css/_style/_tag-plugins/span.js
到themes\butterfly\scripts\tag
目录 - 复制
hexo-theme-volantis/source/css/_style/_tag-plugins/span.styl
到themes\butterfly\source\css\_tags\
目录
使用方法:https://volantis.js.org/v6/tag-plugins/#span
效果:
各种颜色的标签,包括:红色、黄色、绿色、青色、蓝色、灰色。
超大号文字:
Volantis A Wonderful Theme for Hexocheckbox
方法同上
效果:
纯文本测试
支持简单的 markdown 语法
支持自定义颜色
绿色 + 默认选中
黄色 + 默认选中
青色 + 默认选中
蓝色 + 默认选中
增加
减少
叉
link
方法同上
浏览器搞笑标题
1 | // 浏览器搞笑标题 |
首页哔哔(源)
分类标签导航栏(源)
给分类标签添加一个导航栏,参考:Butterfly 分类标签导航栏 | Eurkon
在
\themes\butterfly\scripts\helpers\
目录下新建文件catalog_list.js
1
2
3
4
5
6
7
8
9
10
11hexo.extend.helper.register('catalog_list', function (type) {
let html = ``
hexo.locals.get(type).map(function (item) {
html += `
<div class="catalog-list-item" id="${type + '-' + item.name}">
<a href="/${type}/${item.name}/">${item.name}<sup>${item.length}</sup></a>
</div>
`
})
return html
})显示
分类/标签
时带 emoji,但相应分类/标签
页面不带 emoji 写法1
2
3
4
5
6
7
8
9
10
11hexo.extend.helper.register('catalog_list', function (type) {
let html = ``
hexo.locals.get(type).map(function (item) {
html += `
<div class="catalog-list-item" id="${type + '-' + item.name}">
<a href="/${type}/${item.name}/">${theme.emoji[item.name] + item.name}<sup>${item.length}</sup></a>
</div>
`
})
return html
})样式
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/* 分类目录条、标签目录条 */
#catalog-bar {
padding: 0.4rem 0.8rem;
border-radius: 8px;
display: flex;
margin-bottom: 1rem;
justify-content: space-between;
border: 1.5px solid var(--btn-bg);
transition: .3s;
}
#catalog-bar:hover {
border-color: var(--main);
}
#catalog-bar i {
line-height: inherit;
}
#catalog-list {
margin: 0 0.5rem;
display: flex;
white-space: nowrap;
overflow-x: scroll;
}
#catalog-list::-webkit-scrollbar {
display: none;
}
.catalog-list-item a {
padding: .3rem;
margin: 2px;
font-weight: bold;
border-radius: 5px;
color: var(--font-color);
}
.catalog-list-item:hover a {
background: var(--btn-bg);
color: aliceblue;
}
.catalog-list-item.selected a {
background: var(--btn-hover-color);
color: aliceblue;
border-radius: 5px;
}
a.catalog-more {
min-width: fit-content;
font-weight: bold;
color: var(--font-color);
}
a.catalog-more:hover {
color: var(--btn-bg);
}所在分类/标签高亮JS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22function catalogActive (type) {
let xscroll = document.getElementById('catalog-list')
if (xscroll) {
// 鼠标滚轮滚动
xscroll.addEventListener('mousewheel', function (e) {
//计算鼠标滚轮滚动的距离
xscroll.scrollLeft -= e.wheelDelta / 2
//阻止浏览器默认方法
e.preventDefault()
}, false)
// 高亮当前页面对应的分类或标签
let path = window.location.pathname
path = decodeURIComponent(path)
let pattern = type == 'tags' ? /\/tags\/.*?\// : /\/categories\/.*?\//
if (pattern.test(path)) {
document.getElementById(type + '-' + path.split('/')[2]).classList.add('selected')
}
}
}
catalogActive('categories')
catalogActive('tags')修改分类导航栏
\themes\butterfly\layout\category.pug
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19extends includes/layout.pug
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
+ #catalog-bar
+ i.fa-fw.fas.fa-shapes
+ #catalog-list
+ !=catalog_list("categories")
+ a.catalog-more(href="/categories/")!= '更多'
- .article-sort-title= _p('page.category') + ' - ' + page.category
+articleSort(page.posts)
include includes/pagination.pug修改标签导航栏
\themes\butterfly\layout\tag.pug
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19extends 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
+ #catalog-bar
+ i.fa-fw.fas.fa-tags
+ #catalog-list
+ !=catalog_list("tags")
+ a.catalog-more(href="/tags/")!= '更多'
.article-sort-title= _p('page.tag') + ' - ' + page.tag
+articleSort(page.posts)
include includes/pagination.pug
导航栏增加子菜单
抄张洪的,目前有个问题,导航栏设置居中时子菜单不跟随移动,整不明白😐
修改
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
30
31
32
33
34
35
36
37
38
39nav#nav
#nav-group
span#blog_name
+ div(class='back-home-button')
+ a.back-home-button-icon.fas.fa-grip-vertical
+ div(class='back-menu-list-groups')
+ div(class='back-menu-list-group')
+ div(class='back-menu-list-title') 我的
+ div(class='back-menu-list')
+ <a class="back-menu-item" href="https://i.pblood.com/" rel="external nofollow" title="前往我的引导页" target="_blank">
+ <img class="back-menu-item-icon entered loading" src="https://pblood.oss-cn-hongkong.aliyuncs.com/img/site/logo.png" data-ll-status="loading">
+ <span class="back-menu-item-text">引导页</span></a>
+ <a class="back-menu-item" href="https://blog.pblood.com/" title="前往我的阅览室" target="_blank">
+ <img class="back-menu-item-icon entered loading" src="https://weread.qq.com/favicon.ico" data-ll-status="loading">
+ <span class="back-menu-item-text">阅览室</span></a>
+ div(class='back-menu-list-title') 平行博客
+ div(class='back-menu-list')
+ <a class="back-menu-item" href="https://blog.pblood.com/" target="_blank">
+ <img class="back-menu-item-icon entered loading" src="https://pblood.oss-cn-hongkong.aliyuncs.com/img/site/logo.png" data-ll-status="loading">
+ <span class="back-menu-item-text">主线路</span></a>
+ <a class="back-menu-item" href="https://pblood.gitee.io/" rel="external nofollow" target="_blank">
+ <img class="back-menu-item-icon entered loading" src="https://gitee.com/favicon.ico" data-ll-status="loading">
+ <span class="back-menu-item-text">Gitee线路</span></a>
a#site-name(href=url_for('/')) #[=config.author]
#menus
!=partial('includes/header/menu_item', {}, {cache: true})
#nav-right
if (theme.algolia_search.enable || theme.local_search.enable)
#search-button
a.nav-rightbutton.site-page.social-icon.search
i.fas.fa-search.fa-fw
#darkmode_navswitch
a.nav-rightbutton.site-page.darkmode_switchbutton(onclick="switchDarkMode()")
i.fas.fa-adjust
#toggle-menu
a.nav-rightbutton.site-page
i.fas.fa-bars.fa-fw添加样式
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#nav #blog_name {
display: flex;
}
.back-home-button {
display: flex;
width: 35px;
height: 35px;
padding: 0 ;
align-items: center;
justify-content: center;
margin-right: 4px;
transition: .3s;
border-radius: 8px;
color: var(--font-color);
}
.back-home-button .back-menu-list-groups {
position: absolute;
top: 65px;
left: 1.5rem;
background: var(--global-bg);
border-radius: 12px;
border: var(--style-border);
flex-direction: column;
font-size: 12px;
color: var(--font-color);
transition: 0s;
opacity: 0;
pointer-events: none;
}
.back-home-button .back-menu-list-group {
display: flex;
flex-direction: column;
}
.back-home-button .back-menu-list-group .back-menu-list-title {
margin: 8px 0 0 16px;
transition: .3s;
}
.back-home-button .back-menu-list {
display: flex;
flex-direction: column;
}
.back-home-button .back-menu-list::before {
position: absolute;
top: -15px;
left: 0;
width: 100%;
height: 20px;
content: '';
}
.back-home-button .back-menu-list .back-menu-item {
display: flex;
align-items: center;
margin: 4px 8px;
padding: 4px 8px ;
transition: .3s;
border-radius: 8px;
}
.back-home-button .back-menu-list .back-menu-item .back-menu-item-icon {
width: 24px;
height: 24px;
border-radius: 24px;
background: var(--global-bg);
}
.back-home-button:hover .back-menu-list-groups {
display: flex;
opacity: 1;
transition: .3s;
top: 55px;
pointer-events: auto;
left: 1.5rem;
}
.back-home-button .back-menu-list .back-menu-item .back-menu-item-text {
font-size: var(--global-font-size);
margin-left: .5rem;
color: var(--font-color) ;
}
.page #nav a:hover {
color: var(--btn-bg);
transition: .3s;
box-shadow: var(--btn-bg);
}
.back-home-button .back-menu-list .back-menu-item:hover {
background: var(--btn-bg);
}
@media screen and (max-width: 768px){
.back-home-button:hover .back-menu-list-groups {
width: 100%;
border-radius: 0;
padding-bottom: 8px;
left: 0;
}}
人生倒计时侧边栏
参考:https://blog.xybin.top/2022/countdown-to-life
新建文件source\_data\widget.yml
1 | bottom: |
1 | /*人生倒计时侧边栏*/ |
1 | /*人生倒计时侧边栏*/ |
站点公祭日自动变灰
1 | if(PublicSacrificeDay()){ |
访问统计图表
参考:https://blog.eurkon.com/post/61763977.html
Qexo 后台
使用 Qexo 为博客安装一个后台,在线编辑发布文章,使静态博客也能动态化。
开启文章编辑
在文章标题旁边显示一个编辑按钮,点击会跳转到对应的链接去。
打开主题配置文件
,搜索post_edit:
1 | post_edit: |
美化/特效
阅读模式美化
1 | /* 阅读模式优化 */ |
hide折叠框背景色修改
1 | .toggle |
滚动条美化
1 | /* 滚动条美化 */ |
列表优化
1 | /* 优化 ul>li 列表显示效果 */ |
毛玻璃效果
1 | /* 毛玻璃效果开始!!! */ |
图标相关
动态图标
来自开源项目 l-lin/font-awesome-animation,能让 DOM 的任何元素动起来,主要用于图标,但不止图标
配置:
在主题配置文件
的inject
配置项添加引入font-awesome-animation.min.css
即可,也可下载到本地
1 | inject: |
使用:
以主题默认的 fontawesome 图标为例
对于导航栏、社交卡片的图标可以直接使用,如:
1 | menu: |
HTML用法:
1 | <i class="fas fa-home faa-wrench animated"></i> |
自定义 h1~6 标题图标
文章 h1~6 级标题前 icon,以 h1 为例
1 | #article-container h1:before { |
标题图标旋转
配合风车标题图标很好看
1 | /* 标题图标旋转 */ |
也可以使用上面动态图标的方式旋转
背景相关
去除主页 banner 背景
1 | /* 去除主页 banner 背景 */ |
黑色遮罩效果修改
1 | /* 黑色遮罩效果修改 */ |
加载动画背景修改(源)
修改文件themes\butterfly\source\css\_layout\loading.styl
1 | if hexo-config('preloader') |
渐变色背景
参考链接:https://www.antmoe.com/posts/7198453/
粉蓝色渐变
1 | #web_bg { |
橙青色渐变
1 | #web_bg { |
美美哒渐变
1 | #web_bg { |
动态渐变
1 | @keyframes gradientBG { |
随机背景
1 | //随机背景图片数组,图片可以换成图床链接,注意最后一条后面不要有逗号 |
上升气泡
在主题配置文件
的inject
配置项添加引入js
1 | inject: |
樱花动效
在主题配置文件
的inject
配置项添加引入js
1 | inject: |
星空背景和流星特效
新建\themes\source\js\universe.js
1 | function dark() {window.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame;var n,e,i,h,t=.05,s=document.getElementById("universe"),o=!0,a="180,184,240",r="226,225,142",d="226,225,224",c=[];function f(){n=window.innerWidth,e=window.innerHeight,i=.216*n,s.setAttribute("width",n),s.setAttribute("height",e)}function u(){h.clearRect(0,0,n,e);for(var t=c.length,i=0;i<t;i++){var s=c[i];s.move(),s.fadeIn(),s.fadeOut(),s.draw()}}function y(){this.reset=function(){this.giant=m(3),this.comet=!this.giant&&!o&&m(10),this.x=l(0,n-10),this.y=l(0,e),this.r=l(1.1,2.6),this.dx=l(t,6*t)+(this.comet+1-1)*t*l(50,120)+2*t,this.dy=-l(t,6*t)-(this.comet+1-1)*t*l(50,120),this.fadingOut=null,this.fadingIn=!0,this.opacity=0,this.opacityTresh=l(.2,1-.4*(this.comet+1-1)),this.do=l(5e-4,.002)+.001*(this.comet+1-1)},this.fadeIn=function(){this.fadingIn&&(this.fadingIn=!(this.opacity>this.opacityTresh),this.opacity+=this.do)},this.fadeOut=function(){this.fadingOut&&(this.fadingOut=!(this.opacity<0),this.opacity-=this.do/2,(this.x>n||this.y<0)&&(this.fadingOut=!1,this.reset()))},this.draw=function(){if(h.beginPath(),this.giant)h.fillStyle="rgba("+a+","+this.opacity+")",h.arc(this.x,this.y,2,0,2*Math.PI,!1);else if(this.comet){h.fillStyle="rgba("+d+","+this.opacity+")",h.arc(this.x,this.y,1.5,0,2*Math.PI,!1);for(var t=0;t<30;t++)h.fillStyle="rgba("+d+","+(this.opacity-this.opacity/20*t)+")",h.rect(this.x-this.dx/4*t,this.y-this.dy/4*t-2,2,2),h.fill()}else h.fillStyle="rgba("+r+","+this.opacity+")",h.rect(this.x,this.y,this.r,this.r);h.closePath(),h.fill()},this.move=function(){this.x+=this.dx,this.y+=this.dy,!1===this.fadingOut&&this.reset(),(this.x>n-n/4||this.y<0)&&(this.fadingOut=!0)},setTimeout(function(){o=!1},50)}function m(t){return Math.floor(1e3*Math.random())+1<10*t}function l(t,i){return Math.random()*(i-t)+t}f(),window.addEventListener("resize",f,!1),function(){h=s.getContext("2d");for(var t=0;t<i;t++)c[t]=new y,c[t].reset();u()}(),function t(){document.getElementsByTagName('html')[0].getAttribute('data-theme')=='dark'&&u(),window.requestAnimationFrame(t)}()}; |
1 | /* 背景宇宙星光 */ |
在主题配置文件
的inject
配置项添加引入js、css
1 | inject: |
页脚渐变色滚动动画
1 | /* 页脚footer */ |
页脚跳动的心
- 修改
themes\butterfly\layout\includes\footer.pug
文件,加个爱心图标1
2- .copyright!= `©${nowYear} by ${config.author}`
+ .copyright!= `©${nowYear} <i id="heartbeat" style="color:#FF6A6A" class="fa fa-heartbeat"></i> ${config.author}` - 挂载 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/* 跳动的心 */
#heartbeat {
color: red;
animation: iconAnimate 1.33s ease-in-out infinite;
}
@-moz-keyframes iconAnimate {
0%,
100% {
transform: scale(1);
}
10%,
30% {
transform: scale(0.9);
}
20%,
40%,
60%,
80% {
transform: scale(1.1);
}
50%,
70% {
transform: scale(1.1);
}
}
@-webkit-keyframes iconAnimate {
0%,
100% {
transform: scale(1);
}
10%,
30% {
transform: scale(0.9);
}
20%,
40%,
60%,
80% {
transform: scale(1.1);
}
50%,
70% {
transform: scale(1.1);
}
}
@-o-keyframes iconAnimate {
0%,
100% {
transform: scale(1);
}
10%,
30% {
transform: scale(0.9);
}
20%,
40%,
60%,
80% {
transform: scale(1.1);
}
50%,
70% {
transform: scale(1.1);
}
}
@keyframes iconAnimate {
0%,
100% {
transform: scale(1);
}
10%,
30% {
transform: scale(0.9);
}
20%,
40%,
60%,
80% {
transform: scale(1.1);
}
50%,
70% {
transform: scale(1.1);
}
}