Hexo+Fluid中Onblur事件,离开页面时的标题显示

本文最后更新于 2024年9月16日 晚上

在博客配置下的hexo-blog_inject中,若是没有文件夹则新建,然后在其中新建monitortext.ejs,用于向页面中添加焦点监控代码。

1
2
3
4
5
6
7
8
<% if(theme.fun_features.monitortext.enable) { %>
<script type="text/javascript">
/*窗口监视*/
var originalTitle = document.title;
window.onblur = function(){document.title = "<%- theme.fun_features.monitortext.text %>"};
window.onfocus = function(){document.title = originalTitle};
</script>
<% } %>

然后在hexo-blogpage.js文件,添加以下代码。也可以在官网找到具体描述进阶用法 | Hexo Fluid 用户手册 (fluid-dev.com)

1
2
3
4
5
// 添加页面焦点监控文字
hexo.extend.filter.register('theme_inject', function(injects) {
// 添加页面焦点监控文字(here)
injects.bodyBegin.file('monitortext', "source/_inject/monitortext.ejs");
});

最后编辑主题配置文件,即hexo-blog_config.yml文件,在 fun_features 项下添加:

1
2
3
4
5
6
7
8
9
10
11
12
13
# 一些好玩的功能
# Some fun features
fun_features:
# 监控网页焦点,改变文字
monitortext:
enable: true
text: 你想添加的文字

# 为 subtitle 添加打字机效果
# Typing animation for subtitle
typing:
enable: true

参考

1、https://alec-97.github.io/posts/3644508848/ 2、进阶用法 | Hexo Fluid 用户手册 (fluid-dev.com)


Hexo+Fluid中Onblur事件,离开页面时的标题显示
http://example.com/09Fluid-Onblur/
作者
仓鼠小乐
发布于
2024年9月16日
许可协议