Butterfly美化记录
准备工作
- 在博客根目录下的
source
下创建css
和js
文件夹,用来放魔改的css
和js
文件。 - 在
css
文件夹下创建all.css
文件来存放大多数css
文件,js
同理。
一图流
在all.css
文件中写下如下代码
1 | /* 统一设置页脚和头图的背景为透明 */ |
在主题配置文件[BlogRoot]\_config.butterfly.yml
文件中的inject
配置项的head
子项加入以下代码
1 | inject: |
- 在主题配置文件
[BlogRoot]\_config.butterfly.yml
文件中的index_img
和footer_bg
配置项取消头图与页脚图的加载项避免冗余加载
wowojs动画
安装插件,在博客根目录下打开终端,运行以下指令:
1 | $ npm install hexo-butterfly-wowjs --save |
添加配置信息
在站点配置文件_config.yml
或者主题配置文件_config.butterfly.yml
中添加
1 | # wowjs |
以上是我的配置,具体用法详见hexo-butterfly-wowjs。
导航栏魔改
在all.css
中引入如下css
代码
1 | /* 导航栏 */ |
黑夜霓虹灯
在all.css
中引入如下css
代码
1 | /* 霓虹灯 */ |
星空背景和流星特效
在all.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) }() }; |
在all.css
输入
1 | /* 背景宇宙星光 */ |
在_config.butterfly.yml
的inject
引入
1 | inject: |
引入iconfont自定义图标
新建图标项目
- 访问阿里巴巴矢量图标库,注册登录
- 搜索图标,加到购物车。
- 选择完毕后点击右上角的购物车图标,打开侧栏,选择添加到项目。
- 用fontclass的引用方式即可使用多彩图标,单一项目彩色图标上限是40个图标。
引入图标
在inject
的bottom
引如
示例如下:
1 | <script src="//at.alicdn.com/t/c/font_4819365_t3hcyl6lhar.js"></script> |
更换图标
- 在
_config.butterfly.yml
中更改menu
,写成如下方式
1 | menu: |
- 重写
\themes\butterfly\layout\includes\header\social.pug
1 | each value, title in theme.social |
- 更改大小
在all.css
加入
1 | /* 图标大小 */ |
Butterfly添加全局吸底Aplayer
安装插件
1 | $ npm install --save hexo-tag-aplayer |
关闭 asset_inject
由于需要全局都插入 aplayer
和 meting
资源,为了防止插入重复的资源,需要把 asset_inject
设为 false
在 Hexo 的配置文件中
1 | aplayer: |
开启主题的 aplayerInject
在主题的配置文件中,enable
设为 true
和 per_page
设为 true
1 | # Inject the css and script (aplayer/meting) |
把aplayer
代码插入到主题配置文件的inject.bottom
去
1 | inject: |
最后
如果你想切换页面时,音乐不会中断。请把主题配置文件的pjax
设为 true
参数设置详见hexo-tag-aplayer
。
文章H1~H6标题小风车转动效果
修改主题配置文件
将_config.butterfly.yml
文件的beautify
配置项修改为:
1 | beautify: |
在 all.css
中加入以下代码
1 | /* 文章页H1-H6图标样式效果 */ |
直达底部按钮
在[BlogRoot]\themes\butterfly\layout\includes\rightside.pug
做以下修改:
1 | button#go-up(type="button" title=_p("rightside.back_to_top")) |
页脚
修改footer.pug
将[BlogRoot]/themes/butterfly/layout/includes/footer.pug
替换成如下代码
1 | #footer-wrap |
自定义样式
将以下代码复制到自定义的all.css
中
1 | /* 页脚样式 */ |
计时器
在all.js
中添加
1 | // 运行时间 |
最后引入
网站恶搞标题
在all.js
中添加
1 | //动态标题 |
雪花飘落特效
新建snow.js
[BlogRoot]\source\js\snow.js
中写入
1 | if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) { |
配置css
在all.css
中添加
1 | /* 雪花特效 */ |
引入画布元素
在主题配置文件_config.butterfly.yml
文件的引入js
文件和一个canvas
画布:
1 | inject: |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 轻疯の小栈!