Skip to content
Discussion options

You must be logged in to vote

通过hexo5的注入器功能自定义博客js、css样式

hexo注入器官方文档:https://hexo.io/zh-cn/api/injector.html 和参考的其他博主的博客链接:https://hexo.fluid-dev.com/posts/hexo-injector/ 。总共发现了两种方式:

方法一,先在根目录下scripts/inject.js文件;然后再去新建source/css/navbar.css文件。

// scripts/inject.js
const css = hexo.extend.helper.get('css').bind(hexo);
const js = hexo.extend.helper.get('js').bind(hexo);

hexo.extend.injector.register('head_end', () => {
	return css('/css/navbar.css');
  });
/* source/css/navbar.css */
.navbar {
    z-index: 100;
    position: sticky;
    top: 0;
}

方法二是直接在scripts/inject.js写入以下代码。

hexo.extend.injector.register('head_end', () => `
   <style>
      /* 置顶导航栏样式 */
      .navbar {
         z-index: 100;
         position: sticky;

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by JIeJaitt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant