前言

需要在Hexo下配置next主题

Hexo配置next主题教程:https://www.cnblogs.com/xuande/p/16641543.html

更改配置以后使用素质三连:hexo clean && hexo g && hexo s即可本地看到效果。

  1. hexo clean && hexo g && hexo s

注:部分参考自互联网,感谢各位大佬的教程

主题注入

myblog/themes/next/_config.yml里面找到custom_file_path

把前面的注释去掉,开启主题注入功能

  1. custom_file_path:
  2. style: source/_data/styles.styl

找到myblog\blog\source\_data\styles.styl如果没有就创建一个

资源文件文件在myblog\blog\themes\xuande\source\images目录下配置

鼠标样式

注意开启主题注入功能

myblog\blog\source\_data\styles.styl里面添加如下代码即可

  1. /*鼠标样式*/
  2. * {
  3. cursor: url(/images/Arrow.cur),auto;
  4. }
  5. :active {
  6. // cursor: url(/images/Hand.cur),auto
  7. }
  8. :link {
  9. cursor: url(/images/Hand.cur),auto
  10. }
  11. // 鼠标样式补充
  12. a, span.exturl {
  13. cursor: url(/images/Hand.cur),auto
  14. }
  15. .posts-expand .post-meta time {
  16. cursor: url(/images/Hand.cur),auto
  17. }

这里的url路径就是myblog\blog\themes\xuande\source\images\Arrow.cur,下面同理

背景图片

注意开启主题注入功能

myblog\blog\source\_data\styles.styl里面添加如下代码即可

  1. // 添加背景图片
  2. body {
  3. background: url(/images/background.png);//自己喜欢的图片地址
  4. background-size: cover;
  5. background-repeat: no-repeat;
  6. background-attachment: fixed;
  7. background-position: 50% 50%;
  8. }

自定义回到顶部样式

注意开启主题注入功能

myblog\blog\source\_data\styles.styl里面添加如下代码即可

  1. //自定义回到顶部样式
  2. .back-to-top {
  3. //right: 60px;
  4. width: 70px; //图片素材宽度
  5. height: 900px; //图片素材高度
  6. top: -900px;
  7. bottom: unset;
  8. transition: all .5s ease-in-out;
  9. background: url("/images/scroll.png");
  10. //隐藏箭头图标
  11. > i {
  12. display: none;
  13. }
  14. &.back-to-top-on {
  15. bottom: unset;
  16. top: 100vh < (900px + 200px) ? calc( 100vh - 900px - 200px ) : 0px;
  17. }
  18. }

自定义网站图标

myblog/themes/next/_config.yml里面找到favicon,在这里就可以配置图标的路径,一般情况下只需要设置small和medium两个就可以

  1. favicon:
  2. small: /images/16x16-paimeng.png
  3. medium: /images/32x32-paimeng.png
  4. apple_touch_icon: /images/apple-touch-icon-next.png
  5. safari_pinned_tab: /images/logo.svg

png文件在myblog\blog\themes\xuande\source\images目录下配置即可

效果:

设置侧边栏

myblog/themes/next/_config.yml里面找到sidebar

修改为如下配置:

  1. sidebar:
  2. # Sidebar Position.
  3. position: left
  4. #position: right
  5. # Manual define the sidebar width. If commented, will be default for:
  6. # Muse | Mist: 320
  7. # Pisces | Gemini: 240
  8. #width: 300
  9. # Sidebar Display (only for Muse | Mist), available values:
  10. # - post expand on posts automatically. Default.
  11. # - always expand for all pages automatically.
  12. # - hide expand only when click on the sidebar toggle icon.
  13. # - remove totally remove sidebar including sidebar toggle.
  14. display: post
  15. # Sidebar padding in pixels.
  16. padding: 18
  17. # Sidebar offset from top menubar in pixels (only for Pisces | Gemini).
  18. offset: 12

开启返回顶部功能

myblog/themes/next/_config.yml里面找到back2top

修改为如下配置:

  1. back2top:
  2. enable: true
  3. # Back to top in sidebar.
  4. sidebar: false
  5. # Scroll percent label in b2t button.
  6. scrollpercent: false

侧边栏头像设置

myblog/themes/next/_config.yml里面找到avatr

  1. # 侧栏头像
  2. # Sidebar Avatar
  3. avatar:
  4. url: /images/avatar.png
  5. rounded: true
  6. rotated: true
  7. site_state: true

图片在myblog\blog\themes\xuande\source\images目录下配置即可

鼠标移动特效

myblog\themes\next\source\js\中新建fairyDustCursor.js文件,并添加以下代码

  1. (function fairyDustCursor() {
  2. var possibleColors = ["#D61C59", "#E7D84B", "#1B8798"]
  3. var width = window.innerWidth;
  4. var height = window.innerHeight;
  5. var cursor = {x: width/2, y: width/2};
  6. var particles = [];
  7. function init() {
  8. bindEvents();
  9. loop();
  10. }
  11. // Bind events that are needed
  12. function bindEvents() {
  13. document.addEventListener('mousemove', onMouseMove);
  14. document.addEventListener('touchmove', onTouchMove);
  15. document.addEventListener('touchstart', onTouchMove);
  16. window.addEventListener('resize', onWindowResize);
  17. }
  18. function onWindowResize(e) {
  19. width = window.innerWidth;
  20. height = window.innerHeight;
  21. }
  22. function onTouchMove(e) {
  23. if( e.touches.length > 0 ) {
  24. for( var i = 0; i < e.touches.length; i++ ) {
  25. addParticle( e.touches[i].clientX, e.touches[i].clientY, possibleColors[Math.floor(Math.random()*possibleColors.length)]);
  26. }
  27. }
  28. }
  29. function onMouseMove(e) {
  30. cursor.x = e.clientX;
  31. cursor.y = e.clientY;
  32. addParticle( cursor.x, cursor.y, possibleColors[Math.floor(Math.random()*possibleColors.length)]);
  33. }
  34. function addParticle(x, y, color) {
  35. var particle = new Particle();
  36. particle.init(x, y, color);
  37. particles.push(particle);
  38. }
  39. function updateParticles() {
  40. for( var i = 0; i < particles.length; i++ ) {
  41. particles[i].update();
  42. }
  43. for( var i = particles.length -1; i >= 0; i-- ) {
  44. if( particles[i].lifeSpan < 0 ) {
  45. particles[i].die();
  46. particles.splice(i, 1);
  47. }
  48. }
  49. }
  50. function loop() {
  51. requestAnimationFrame(loop);
  52. updateParticles();
  53. }
  54. function Particle() {
  55. this.character = "*";
  56. this.lifeSpan = 120; //ms
  57. this.initialStyles ={
  58. "position": "fixed",
  59. "top": "0", //必须加
  60. "display": "block",
  61. "pointerEvents": "none",
  62. "z-index": "10000000",
  63. "fontSize": "20px",
  64. "will-change": "transform"
  65. };
  66. this.init = function(x, y, color) {
  67. this.velocity = {
  68. x: (Math.random() < 0.5 ? -1 : 1) * (Math.random() / 2),
  69. y: 1
  70. };
  71. this.position = {x: x - 10, y: y - 20};
  72. this.initialStyles.color = color;
  73. console.log(color);
  74. this.element = document.createElement('span');
  75. this.element.innerHTML = this.character;
  76. applyProperties(this.element, this.initialStyles);
  77. this.update();
  78. document.body.appendChild(this.element);
  79. };
  80. this.update = function() {
  81. this.position.x += this.velocity.x;
  82. this.position.y += this.velocity.y;
  83. this.lifeSpan--;
  84. this.element.style.transform = "translate3d(" + this.position.x + "px," + this.position.y + "px,0) scale(" + (this.lifeSpan / 120) + ")";
  85. }
  86. this.die = function() {
  87. this.element.parentNode.removeChild(this.element);
  88. }
  89. }
  90. function applyProperties( target, properties ) {
  91. for( var key in properties ) {
  92. target.style[ key ] = properties[ key ];
  93. }
  94. }
  95. init();
  96. })();

然后在myblog\themes\next\layout_layout.njk文件里内部引用:

  1. <!-- 樱花特效 -->
  2. {% if theme.sakura.enable %}
  3. <script async src="/js/src/fairyDustCursor.js"></script>
  4. {% endif %}

最后打开myblog/themes/next/_config.yml在最下面添加如下代码

  1. # 樱花飘落动特效
  2. sakura:
  3. enable: true

鼠标点击特效

首先在themes\next\source\js\cursor\ 目录下创建love.min.js

在里面添加如下代码:

  1. !function(e,t,a){function n(){c(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"),o(),r()}function r(){for(var e=0;e<d.length;e++)d[e].alpha<=0?(t.body.removeChild(d[e].el),d.splice(e,1)):(d[e].y--,d[e].scale+=.004,d[e].alpha-=.013,d[e].el.style.cssText="left:"+d[e].x+"px;top:"+d[e].y+"px;opacity:"+d[e].alpha+";transform:scale("+d[e].scale+","+d[e].scale+") rotate(45deg);background:"+d[e].color+";z-index:99999");requestAnimationFrame(r)}function o(){var t="function"==typeof e.onclick&&e.onclick;e.onclick=function(e){t&&t(),i(e)}}function i(e){var a=t.createElement("div");a.className="heart",d.push({el:a,x:e.clientX-5,y:e.clientY-5,scale:1,alpha:1,color:s()}),t.body.appendChild(a)}function c(e){var a=t.createElement("style");a.type="text/css";try{a.appendChild(t.createTextNode(e))}catch(t){a.styleSheet.cssText=e}t.getElementsByTagName("head")[0].appendChild(a)}function s(){return"rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random())+")"}var d=[];e.requestAnimationFrame=function(){return e.requestAnimationFrame||e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame||function(e){setTimeout(e,1e3/60)}}(),n()}(window,document);

text.js浮出文字代码

  1. var a_idx = 0;
  2. jQuery(document).ready(function($) {
  3. $("body").click(function(e) {
  4. var a = new Array("喜欢我", "不喜欢我");
  5. var $i = $("<span/>").text(a[a_idx]);
  6. var x = e.pageX,
  7. y = e.pageY;
  8. $i.css({
  9. "z-index": 99999,
  10. "top": y - 28,
  11. "left": x - a[a_idx].length * 8,
  12. "position": "absolute",
  13. "color": "#ff7a45"
  14. });
  15. $("body").append($i);
  16. $i.animate({
  17. "top": y - 180,
  18. "opacity": 0
  19. }, 1500, function() {
  20. $i.remove();
  21. });
  22. a_idx = (a_idx + 1) % a.length;
  23. });
  24. });

fireworks.js礼花特效代码

  1. class Circle {
  2. constructor({ origin, speed, color, angle, context }) {
  3. this.origin = origin
  4. this.position = { ...this.origin }
  5. this.color = color
  6. this.speed = speed
  7. this.angle = angle
  8. this.context = context
  9. this.renderCount = 0
  10. }
  11. draw() {
  12. this.context.fillStyle = this.color
  13. this.context.beginPath()
  14. this.context.arc(this.position.x, this.position.y, 2, 0, Math.PI * 2)
  15. this.context.fill()
  16. }
  17. move() {
  18. this.position.x = (Math.sin(this.angle) * this.speed) + this.position.x
  19. this.position.y = (Math.cos(this.angle) * this.speed) + this.position.y + (this.renderCount * 0.3)
  20. this.renderCount++
  21. }
  22. }
  23. class Boom {
  24. constructor ({ origin, context, circleCount = 16, area }) {
  25. this.origin = origin
  26. this.context = context
  27. this.circleCount = circleCount
  28. this.area = area
  29. this.stop = false
  30. this.circles = []
  31. }
  32. randomArray(range) {
  33. const length = range.length
  34. const randomIndex = Math.floor(length * Math.random())
  35. return range[randomIndex]
  36. }
  37. randomColor() {
  38. const range = ['8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
  39. return '#' + this.randomArray(range) + this.randomArray(range) + this.randomArray(range) + this.randomArray(range) + this.randomArray(range) + this.randomArray(range)
  40. }
  41. randomRange(start, end) {
  42. return (end - start) * Math.random() + start
  43. }
  44. init() {
  45. for(let i = 0; i < this.circleCount; i++) {
  46. const circle = new Circle({
  47. context: this.context,
  48. origin: this.origin,
  49. color: this.randomColor(),
  50. angle: this.randomRange(Math.PI - 1, Math.PI + 1),
  51. speed: this.randomRange(1, 6)
  52. })
  53. this.circles.push(circle)
  54. }
  55. }
  56. move() {
  57. this.circles.forEach((circle, index) => {
  58. if (circle.position.x > this.area.width || circle.position.y > this.area.height) {
  59. return this.circles.splice(index, 1)
  60. }
  61. circle.move()
  62. })
  63. if (this.circles.length == 0) {
  64. this.stop = true
  65. }
  66. }
  67. draw() {
  68. this.circles.forEach(circle => circle.draw())
  69. }
  70. }
  71. class CursorSpecialEffects {
  72. constructor() {
  73. this.computerCanvas = document.createElement('canvas')
  74. this.renderCanvas = document.createElement('canvas')
  75. this.computerContext = this.computerCanvas.getContext('2d')
  76. this.renderContext = this.renderCanvas.getContext('2d')
  77. this.globalWidth = window.innerWidth
  78. this.globalHeight = window.innerHeight
  79. this.booms = []
  80. this.running = false
  81. }
  82. handleMouseDown(e) {
  83. const boom = new Boom({
  84. origin: { x: e.clientX, y: e.clientY },
  85. context: this.computerContext,
  86. area: {
  87. width: this.globalWidth,
  88. height: this.globalHeight
  89. }
  90. })
  91. boom.init()
  92. this.booms.push(boom)
  93. this.running || this.run()
  94. }
  95. handlePageHide() {
  96. this.booms = []
  97. this.running = false
  98. }
  99. init() {
  100. const style = this.renderCanvas.style
  101. style.position = 'fixed'
  102. style.top = style.left = 0
  103. style.zIndex = '999999999999999999999999999999999999999999'
  104. style.pointerEvents = 'none'
  105. style.width = this.renderCanvas.width = this.computerCanvas.width = this.globalWidth
  106. style.height = this.renderCanvas.height = this.computerCanvas.height = this.globalHeight
  107. document.body.append(this.renderCanvas)
  108. window.addEventListener('mousedown', this.handleMouseDown.bind(this))
  109. window.addEventListener('pagehide', this.handlePageHide.bind(this))
  110. }
  111. run() {
  112. this.running = true
  113. if (this.booms.length == 0) {
  114. return this.running = false
  115. }
  116. requestAnimationFrame(this.run.bind(this))
  117. this.computerContext.clearRect(0, 0, this.globalWidth, this.globalHeight)
  118. this.renderContext.clearRect(0, 0, this.globalWidth, this.globalHeight)
  119. this.booms.forEach((boom, index) => {
  120. if (boom.stop) {
  121. return this.booms.splice(index, 1)
  122. }
  123. boom.move()
  124. boom.draw()
  125. })
  126. this.renderContext.drawImage(this.computerCanvas, 0, 0, this.globalWidth, this.globalHeight)
  127. }
  128. }
  129. const cursorSpecialEffects = new CursorSpecialEffects()
  130. cursorSpecialEffects.init()

然后我们在主题自定义布局文件hexo/source/_data/body-end.swig中,没有就创建一个,在里面添加以下代码:

  1. {# 鼠标点击特效 #}
  2. {% if theme.cursor_effect == "fireworks" %}
  3. <script async src="/js/cursor/fireworks.js"></script>
  4. {% elseif theme.cursor_effect == "explosion" %}
  5. <canvas class="fireworks" style="position: fixed;left: 0;top: 0;z-index: 1; pointer-events: none;" ></canvas>
  6. <script src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script>
  7. <script async src="/js/cursor/explosion.min.js"></script>
  8. {% elseif theme.cursor_effect == "love" %}
  9. <script async src="/js/cursor/love.min.js"></script>
  10. {% elseif theme.cursor_effect == "text" %}
  11. <script async src="/js/cursor/text.js"></script>
  12. {% endif %}

在主题注入里取消 body-end.swig 的注释(主题注入教程在上面)

  1. custom_file_path:
  2. bodyEnd: source/_data/body-end.swig

最后打开myblog/themes/next/_config.yml在最下面添加如下代码

  1. # 鼠标点击特效
  2. # mouse click effect: fireworks | explosion | love | text
  3. cursor_effect: love
  4. # 打字特效
  5. # typing effect
  6. typing_effect:
  7. colorful: false # 礼花特效
  8. shake: false # 震动特效

自定义侧栏时间

效果如图:

首先打开myblog\blog\themes\xuande\layout\_macro\sidebar.njk

添加如下代码:

  1. <!-- canvas粒子时钟 -->
  2. {% if theme.diy_time.clock.enable %}
  3. {% include '../_custom/clock.swig' %}
  4. {% endif %}
  5. <!-- 网站运行时间 -->
  6. {% if theme.diy_time.runtime.enable %}
  7. {% include '../_custom/runtime.swig' %}
  8. {% endif %}

然后打开myblog\blog\themes\xuande\layout_custom新建clock.swig文件

在里面添加如下代码:

  1. <!-- canvas粒子时钟 https://www.cnblogs.com/xiaohuochai/p/6368039.html
  2. https://www.html5tricks.com/html5-canvas-dance-time.html
  3. -->
  4. <div id="">
  5. <canvas id="canvas" style="width:60%;">
  6. </div>
  7. <script async>
  8. (function(){
  9. var WINDOW_WIDTH = 820;
  10. var WINDOW_HEIGHT = 250;
  11. var RADIUS = 7; //球半径
  12. var NUMBER_GAP = 10; //数字之间的间隙
  13. var u=0.65; //碰撞能量损耗系数
  14. var context; //Canvas绘制上下文
  15. var balls = []; //存储彩色的小球
  16. const colors = ["#33B5E5","#0099CC","#AA66CC","#9933CC","#99CC00","#669900","#FFBB33","#FF8800","#FF4444","#CC0000"]; //彩色小球的颜色
  17. var currentNums = []; //屏幕显示的8个字符
  18. var digit =
  19. [
  20. [
  21. [0,0,1,1,1,0,0],
  22. [0,1,1,0,1,1,0],
  23. [1,1,0,0,0,1,1],
  24. [1,1,0,0,0,1,1],
  25. [1,1,0,0,0,1,1],
  26. [1,1,0,0,0,1,1],
  27. [1,1,0,0,0,1,1],
  28. [1,1,0,0,0,1,1],
  29. [0,1,1,0,1,1,0],
  30. [0,0,1,1,1,0,0]
  31. ],//0
  32. [
  33. [0,0,0,1,1,0,0],
  34. [0,1,1,1,1,0,0],
  35. [0,0,0,1,1,0,0],
  36. [0,0,0,1,1,0,0],
  37. [0,0,0,1,1,0,0],
  38. [0,0,0,1,1,0,0],
  39. [0,0,0,1,1,0,0],
  40. [0,0,0,1,1,0,0],
  41. [0,0,0,1,1,0,0],
  42. [1,1,1,1,1,1,1]
  43. ],//1
  44. [
  45. [0,1,1,1,1,1,0],
  46. [1,1,0,0,0,1,1],
  47. [0,0,0,0,0,1,1],
  48. [0,0,0,0,1,1,0],
  49. [0,0,0,1,1,0,0],
  50. [0,0,1,1,0,0,0],
  51. [0,1,1,0,0,0,0],
  52. [1,1,0,0,0,0,0],
  53. [1,1,0,0,0,1,1],
  54. [1,1,1,1,1,1,1]
  55. ],//2
  56. [
  57. [1,1,1,1,1,1,1],
  58. [0,0,0,0,0,1,1],
  59. [0,0,0,0,1,1,0],
  60. [0,0,0,1,1,0,0],
  61. [0,0,1,1,1,0,0],
  62. [0,0,0,0,1,1,0],
  63. [0,0,0,0,0,1,1],
  64. [0,0,0,0,0,1,1],
  65. [1,1,0,0,0,1,1],
  66. [0,1,1,1,1,1,0]
  67. ],//3
  68. [
  69. [0,0,0,0,1,1,0],
  70. [0,0,0,1,1,1,0],
  71. [0,0,1,1,1,1,0],
  72. [0,1,1,0,1,1,0],
  73. [1,1,0,0,1,1,0],
  74. [1,1,1,1,1,1,1],
  75. [0,0,0,0,1,1,0],
  76. [0,0,0,0,1,1,0],
  77. [0,0,0,0,1,1,0],
  78. [0,0,0,1,1,1,1]
  79. ],//4
  80. [
  81. [1,1,1,1,1,1,1],
  82. [1,1,0,0,0,0,0],
  83. [1,1,0,0,0,0,0],
  84. [1,1,1,1,1,1,0],
  85. [0,0,0,0,0,1,1],
  86. [0,0,0,0,0,1,1],
  87. [0,0,0,0,0,1,1],
  88. [0,0,0,0,0,1,1],
  89. [1,1,0,0,0,1,1],
  90. [0,1,1,1,1,1,0]
  91. ],//5
  92. [
  93. [0,0,0,0,1,1,0],
  94. [0,0,1,1,0,0,0],
  95. [0,1,1,0,0,0,0],
  96. [1,1,0,0,0,0,0],
  97. [1,1,0,1,1,1,0],
  98. [1,1,0,0,0,1,1],
  99. [1,1,0,0,0,1,1],
  100. [1,1,0,0,0,1,1],
  101. [1,1,0,0,0,1,1],
  102. [0,1,1,1,1,1,0]
  103. ],//6
  104. [
  105. [1,1,1,1,1,1,1],
  106. [1,1,0,0,0,1,1],
  107. [0,0,0,0,1,1,0],
  108. [0,0,0,0,1,1,0],
  109. [0,0,0,1,1,0,0],
  110. [0,0,0,1,1,0,0],
  111. [0,0,1,1,0,0,0],
  112. [0,0,1,1,0,0,0],
  113. [0,0,1,1,0,0,0],
  114. [0,0,1,1,0,0,0]
  115. ],//7
  116. [
  117. [0,1,1,1,1,1,0],
  118. [1,1,0,0,0,1,1],
  119. [1,1,0,0,0,1,1],
  120. [1,1,0,0,0,1,1],
  121. [0,1,1,1,1,1,0],
  122. [1,1,0,0,0,1,1],
  123. [1,1,0,0,0,1,1],
  124. [1,1,0,0,0,1,1],
  125. [1,1,0,0,0,1,1],
  126. [0,1,1,1,1,1,0]
  127. ],//8
  128. [
  129. [0,1,1,1,1,1,0],
  130. [1,1,0,0,0,1,1],
  131. [1,1,0,0,0,1,1],
  132. [1,1,0,0,0,1,1],
  133. [0,1,1,1,0,1,1],
  134. [0,0,0,0,0,1,1],
  135. [0,0,0,0,0,1,1],
  136. [0,0,0,0,1,1,0],
  137. [0,0,0,1,1,0,0],
  138. [0,1,1,0,0,0,0]
  139. ],//9
  140. [
  141. [0,0,0,0],
  142. [0,0,0,0],
  143. [0,1,1,0],
  144. [0,1,1,0],
  145. [0,0,0,0],
  146. [0,0,0,0],
  147. [0,1,1,0],
  148. [0,1,1,0],
  149. [0,0,0,0],
  150. [0,0,0,0]
  151. ]//:
  152. ];
  153. function drawDatetime(cxt){
  154. var nums = [];
  155. context.fillStyle="#005eac"
  156. var date = new Date();
  157. var offsetX = 70, offsetY = 30;
  158. var hours = date.getHours();
  159. var num1 = Math.floor(hours/10);
  160. var num2 = hours%10;
  161. nums.push({num: num1});
  162. nums.push({num: num2});
  163. nums.push({num: 10}); //冒号
  164. var minutes = date.getMinutes();
  165. var num1 = Math.floor(minutes/10);
  166. var num2 = minutes%10;
  167. nums.push({num: num1});
  168. nums.push({num: num2});
  169. nums.push({num: 10}); //冒号
  170. var seconds = date.getSeconds();
  171. var num1 = Math.floor(seconds/10);
  172. var num2 = seconds%10;
  173. nums.push({num: num1});
  174. nums.push({num: num2});
  175. for(var x = 0;x<nums.length;x++){
  176. nums[x].offsetX = offsetX;
  177. offsetX = drawSingleNumber(offsetX,offsetY, nums[x].num,cxt);
  178. //两个数字连一块,应该间隔一些距离
  179. if(x<nums.length-1){
  180. if((nums[x].num!=10) &&(nums[x+1].num!=10)){
  181. offsetX+=NUMBER_GAP;
  182. }
  183. }
  184. }
  185. //说明这是初始化
  186. if(currentNums.length ==0){
  187. currentNums = nums;
  188. }else{
  189. //进行比较
  190. for(var index = 0;index<currentNums.length;index++){
  191. if(currentNums[index].num!=nums[index].num){
  192. //不一样时,添加彩色小球
  193. addBalls(nums[index]);
  194. currentNums[index].num=nums[index].num;
  195. }
  196. }
  197. }
  198. renderBalls(cxt);
  199. updateBalls();
  200. return date;
  201. }
  202. function addBalls (item) {
  203. var num = item.num;
  204. var numMatrix = digit[num];
  205. for(var y = 0;y<numMatrix.length;y++){
  206. for(var x = 0;x<numMatrix[y].length;x++){
  207. if(numMatrix[y][x]==1){
  208. var ball={
  209. offsetX:item.offsetX+RADIUS+RADIUS*2*x,
  210. offsetY:30+RADIUS+RADIUS*2*y,
  211. color:colors[Math.floor(Math.random()*colors.length)],
  212. g:1.5+Math.random(),
  213. vx:Math.pow(-1, Math.ceil(Math.random()*10))*4+Math.random(),
  214. vy:-5
  215. }
  216. balls.push(ball);
  217. }
  218. }
  219. }
  220. }
  221. function renderBalls(cxt){
  222. for(var index = 0;index<balls.length;index++){
  223. cxt.beginPath();
  224. cxt.fillStyle=balls[index].color;
  225. cxt.arc(balls[index].offsetX, balls[index].offsetY, RADIUS, 0, 2*Math.PI);
  226. cxt.fill();
  227. }
  228. }
  229. function updateBalls () {
  230. var i =0;
  231. for(var index = 0;index<balls.length;index++){
  232. var ball = balls[index];
  233. ball.offsetX += ball.vx;
  234. ball.offsetY += ball.vy;
  235. ball.vy+=ball.g;
  236. if(ball.offsetY > (WINDOW_HEIGHT-RADIUS)){
  237. ball.offsetY= WINDOW_HEIGHT-RADIUS;
  238. ball.vy=-ball.vy*u;
  239. }
  240. if(ball.offsetX>RADIUS&&ball.offsetX<(WINDOW_WIDTH-RADIUS)){
  241. balls[i]=balls[index];
  242. i++;
  243. }
  244. }
  245. //去除出边界的球
  246. for(;i<balls.length;i++){
  247. balls.pop();
  248. }
  249. }
  250. function drawSingleNumber(offsetX, offsetY, num, cxt){
  251. var numMatrix = digit[num];
  252. for(var y = 0;y<numMatrix.length;y++){
  253. for(var x = 0;x<numMatrix[y].length;x++){
  254. if(numMatrix[y][x]==1){
  255. cxt.beginPath();
  256. cxt.arc(offsetX+RADIUS+RADIUS*2*x,offsetY+RADIUS+RADIUS*2*y,RADIUS,0,2*Math.PI);
  257. cxt.fill();
  258. }
  259. }
  260. }
  261. cxt.beginPath();
  262. offsetX += numMatrix[0].length*RADIUS*2;
  263. return offsetX;
  264. }
  265. var canvas = document.getElementById("canvas");
  266. canvas.width=WINDOW_WIDTH;
  267. canvas.height=WINDOW_HEIGHT;
  268. context = canvas.getContext("2d");
  269. //记录当前绘制的时刻
  270. var currentDate = new Date();
  271. setInterval(function(){
  272. //清空整个Canvas,重新绘制内容
  273. context.clearRect(0, 0, context.canvas.width, context.canvas.height);
  274. drawDatetime(context);
  275. }, 50)
  276. })();
  277. </script>

最后打开myblog/themes/next/_config.yml在最下面添加如下代码

  1. # 侧栏自定义时间
  2. diy_time:
  3. runtime:
  4. enable: true #运行时间
  5. birthday: "07/25/2022 12:00:00"
  6. clock:
  7. enable: true # 粒子

live2d高级看板娘

简单Demo

导入 Font Awesome 图标支持

  1. <link rel="stylesheet" href="https://fastly.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css">

把下面代码放入你的博客根目录下\themes\xuande\layout\_layout.njk里面(也可能是_layout.swig,取决于你的next版本)

  1. <script src="https://fastly.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/autoload.js"></script>

放置位置如下:

最后在打开myblog/themes/next/_config.yml在最下面添加如下代码

  1. # 看板娘
  2. live2d:
  3. enable: true

注:也可以把这两行代码删掉,可以防止与自带看板娘冲突

  1. {% if theme.live2d.enable %}
  2. {% endif %}

这样一个萌萌哒的看板娘就出来啦

注:如果跟自带的看板娘冲突,请先卸载自带的看板娘

自定义看板娘

首先,先把文件克隆到你的博客的source目录下(根目录下和主题目录下的sources都可以)

  1. git clone https://github.com/stevenjoezhang/live2d-widget.git

其次,更改一下引用路径

_layout.njk:

source\live2d\autoload.js

这样,就可以在waifu-tips.jswaifu-tips.json里面更改活动检测和对话内容了

(注:gitee有文字检测功能,如果提示违规就删掉waifu-tips.json里的"click"对话的部分文字,这gitee的检测机制我是真的服。。。。)

补充

以上是在本地更改,也可以在GitHub上Fork一份,然后用cdn加载也是可以的,条条大路通罗马嘛

如果cdn访问不了的话,不妨试试api

source\live2d\autoload.js

添加看板娘模型:

这里我没试过,但思路是有的,留个期待,以后完善

轮播图设置

第一步:添加配置

找到博客目录下的themes\next\layout下的index文件

添加下面这一行代码

  1. {% include '_macro/carousel.swig' %}

第二步:添加文件

themes\next\layout\macro文件下创建carousel.swig文件。

写入以下内容:

  1. {% if theme.carousel.enable %}
  2. <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
  3. <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
  4. <style type="text/css">
  5. .glyphicon-chevron-left:before{
  6. content: "《"
  7. }
  8. .glyphicon-chevron-right:before{
  9. content: "》"
  10. }
  11. @media (max-width: 767px){
  12. .rights{
  13. display: none;
  14. }
  15. .carousel{
  16. width: 100% !important;
  17. height: 100% !important;
  18. }
  19. .slide{
  20. width: 100% !important;
  21. height: 100% !important;
  22. }
  23. }
  24. .carousel{
  25. width: 100%;
  26. height: 100%;
  27. position: relative;
  28. }
  29. .carousel-inner {
  30. position: relative;
  31. overflow: hidden;
  32. width: 100%;
  33. }
  34. .carousel-inner > .item {
  35. display: none;
  36. position: relative;
  37. -webkit-transition: 0.6s ease-in-out left;
  38. -o-transition: 0.6s ease-in-out left;
  39. transition: 0.6s ease-in-out left;
  40. }
  41. .carousel-inner > .item > img,
  42. .carousel-inner > .item > a > img {
  43. line-height: 1;
  44. }
  45. @media all and (transform-3d), (-webkit-transform-3d) {
  46. .carousel-inner > .item {
  47. -webkit-transition: -webkit-transform 0.6s ease-in-out;
  48. -moz-transition: -moz-transform 0.6s ease-in-out;
  49. -o-transition: -o-transform 0.6s ease-in-out;
  50. transition: transform 0.6s ease-in-out;
  51. -webkit-backface-visibility: hidden;
  52. -moz-backface-visibility: hidden;
  53. backface-visibility: hidden;
  54. -webkit-perspective: 1000px;
  55. -moz-perspective: 1000px;
  56. perspective: 1000px;
  57. }
  58. .carousel-inner > .item.next,
  59. .carousel-inner > .item.active.right {
  60. -webkit-transform: translate3d(100%, 0, 0);
  61. transform: translate3d(100%, 0, 0);
  62. left: 0;
  63. }
  64. .carousel-inner > .item.prev,
  65. .carousel-inner > .item.active.left {
  66. -webkit-transform: translate3d(-100%, 0, 0);
  67. transform: translate3d(-100%, 0, 0);
  68. left: 0;
  69. }
  70. .carousel-inner > .item.next.left,
  71. .carousel-inner > .item.prev.right,
  72. .carousel-inner > .item.active {
  73. -webkit-transform: translate3d(0, 0, 0);
  74. transform: translate3d(0, 0, 0);
  75. left: 0;
  76. }
  77. }
  78. .carousel-inner > .active,
  79. .carousel-inner > .next,
  80. .carousel-inner > .prev {
  81. display: block;
  82. }
  83. .carousel-inner > .active {
  84. left: 0;
  85. }
  86. .carousel-inner > .next,
  87. .carousel-inner > .prev {
  88. position: absolute;
  89. top: 0;
  90. width: 100%;
  91. }
  92. .carousel-inner > .next {
  93. left: 100%;
  94. }
  95. .carousel-inner > .prev {
  96. left: -100%;
  97. }
  98. .carousel-inner > .next.left,
  99. .carousel-inner > .prev.right {
  100. left: 0;
  101. }
  102. .carousel-inner > .active.left {
  103. left: -100%;
  104. }
  105. .carousel-inner > .active.right {
  106. left: 100%;
  107. }
  108. .carousel-control {
  109. position: absolute;
  110. top: 0;
  111. left: 0;
  112. bottom: 0;
  113. width: 15%;
  114. opacity: 0.5;
  115. filter: alpha(opacity=50);
  116. font-size: 20px;
  117. color: #fff;
  118. text-align: center;
  119. text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  120. background-color: rgba(0, 0, 0, 0);
  121. }
  122. .carousel-control.left {
  123. background-image: -webkit-linear-gradient(left, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.0001) 100%);
  124. background-image: -o-linear-gradient(left, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.0001) 100%);
  125. background-image: linear-gradient(to right, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.0001) 100%);
  126. background-repeat: repeat-x;
  127. filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#80000000', endColorstr='#00000000', GradientType=1);
  128. }
  129. .carousel-control.right {
  130. left: auto;
  131. right: 0;
  132. background-image: -webkit-linear-gradient(left, rgba(0, 0, 0, 0.0001) 0%, rgba(0, 0, 0, 0.5) 100%);
  133. background-image: -o-linear-gradient(left, rgba(0, 0, 0, 0.0001) 0%, rgba(0, 0, 0, 0.5) 100%);
  134. background-image: linear-gradient(to right, rgba(0, 0, 0, 0.0001) 0%, rgba(0, 0, 0, 0.5) 100%);
  135. background-repeat: repeat-x;
  136. filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00000000', endColorstr='#80000000', GradientType=1);
  137. }
  138. .carousel-control:hover,
  139. .carousel-control:focus {
  140. outline: 0;
  141. color: #fff;
  142. text-decoration: none;
  143. opacity: 0.9;
  144. filter: alpha(opacity=90);
  145. }
  146. .carousel-control .icon-prev,
  147. .carousel-control .icon-next,
  148. .carousel-control .glyphicon-chevron-left,
  149. .carousel-control .glyphicon-chevron-right {
  150. position: absolute;
  151. top: 50%;
  152. margin-top: -10px;
  153. z-index: 5;
  154. display: inline-block;
  155. }
  156. .carousel-control .icon-prev,
  157. .carousel-control .glyphicon-chevron-left {
  158. left: 50%;
  159. margin-left: -10px;
  160. }
  161. .carousel-control .icon-next,
  162. .carousel-control .glyphicon-chevron-right {
  163. right: 50%;
  164. margin-right: -10px;
  165. }
  166. .carousel-control .icon-prev,
  167. .carousel-control .icon-next {
  168. width: 20px;
  169. height: 20px;
  170. line-height: 1;
  171. font-family: serif;
  172. }
  173. .carousel-control .icon-prev:before {
  174. content: '\2039';
  175. }
  176. .carousel-control .icon-next:before {
  177. content: '\203a';
  178. }
  179. .carousel-indicators {
  180. position: absolute;
  181. bottom: 10px;
  182. left: 50%;
  183. z-index: 15;
  184. width: 60%;
  185. margin-left: -30%;
  186. padding-left: 0;
  187. list-style: none;
  188. text-align: center;
  189. }
  190. .carousel-indicators li {
  191. display: inline-block;
  192. width: 10px;
  193. height: 10px;
  194. margin: 1px;
  195. text-indent: -999px;
  196. border: 1px solid #fff;
  197. border-radius: 10px;
  198. cursor: pointer;
  199. background-color: #000 \9;
  200. background-color: rgba(0, 0, 0, 0);
  201. }
  202. .carousel-indicators .active {
  203. margin: 0;
  204. width: 12px;
  205. height: 12px;
  206. background-color: #fff;
  207. }
  208. .carousel-caption {
  209. position: absolute;
  210. left: 15%;
  211. right: 15%;
  212. bottom: 20px;
  213. z-index: 10;
  214. padding-top: 20px;
  215. padding-bottom: 20px;
  216. color: #fff;
  217. text-align: center;
  218. text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  219. }
  220. .carousel-caption .btn {
  221. text-shadow: none;
  222. }
  223. @media screen and (min-width: 768px) {
  224. .carousel-control .glyphicon-chevron-left,
  225. .carousel-control .glyphicon-chevron-right,
  226. .carousel-control .icon-prev,
  227. .carousel-control .icon-next {
  228. width: 30px;
  229. height: 30px;
  230. margin-top: -10px;
  231. font-size: 30px;
  232. }
  233. .carousel-control .glyphicon-chevron-left,
  234. .carousel-control .icon-prev {
  235. margin-left: -10px;
  236. }
  237. .carousel-control .glyphicon-chevron-right,
  238. .carousel-control .icon-next {
  239. margin-right: -10px;
  240. }
  241. .carousel-caption {
  242. left: 20%;
  243. right: 20%;
  244. padding-bottom: 30px;
  245. }
  246. .carousel-indicators {
  247. bottom: 20px;
  248. }
  249. }
  250. </style>
  251. <div width="100%" height="320px" style="border: 0px; overflow: hidden; border-radius: 10px;" scrolling="no">
  252. <div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="3500" >
  253. <!-- 轮播(Carousel)指标 -->
  254. <ol class="carousel-indicators">
  255. {% set index = 0 %}
  256. {% for item in theme.carousel.item %}
  257. <li data-target="#myCarousel" data-slide-to="{{index}}"></li>
  258. {% set index = index+1 %}
  259. {% endfor %}
  260. </ol>
  261. <!-- 轮播(Carousel)项目 -->
  262. <div class="carousel-inner" style="height: 280px; border-radius: 10px; width: 100%;">
  263. {% set act = 0 %}
  264. {% for item in theme.carousel.item %}
  265. {% if act===0 %}
  266. <a class="item active" href="{{ url_for(item.link) }}" target="_blank" style="height: 100%;">
  267. <img src="{{item.img}}" style="width: 100%; height: 100%" >
  268. </a>
  269. {% set act = 1 %}
  270. {% elseif act===1 %}
  271. <a class="item" href="{{ url_for(item.link) }}" target="_blank" style="height: 100%;">
  272. <img src="{{item.img}}" style="width: 100%; height: 100%;" >
  273. </a>
  274. {% endif %}
  275. {% endfor %}
  276. </div>
  277. <!-- 轮播(Carousel)导航 -->
  278. <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
  279. <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
  280. </a>
  281. <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
  282. <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
  283. </a>
  284. </div>
  285. </div>
  286. {% endif %}

第三步:配置文件中配置图片及链接

在next主题目录下的_config.xml主题配置文件中末尾添加如下配置:

  1. # 主页轮播图 使用 620x310 的图片
  2. #Home carousel map, from means link, img means picture
  3. carousel:
  4. enable: true
  5. item: [
  6. {
  7. 'link':'文章链接1',
  8. 'img':'图片链接1'
  9. },
  10. {
  11. 'link':'文章链接2',
  12. 'img':'图片链接2'
  13. },
  14. ]

ps:注意:开启这种轮播图形式的时候,在主题配置文件中不要开启fancybox,这个设置需要设置为false,不然在点击图片进行跳转时会出现The requested content cannot be loaded.Please try again later.错误

Hexo+next主题美化的更多相关文章

  1. Hexo+Butterfly主题美化

    前言 本博客基于Hexo框架搭建,用到 hexo-theme-butterfly 主题(本人博客Butterfly版本3.4.0),hexo-theme-butterfly是基于Molunerfinn ...

  2. Hexo博客搭建以及Next主题美化的经验之谈

    这并不是一篇博客搭建教程.内容主要包含个人对于Hexo博客搭建的心得,Next6.0主题美化的部分建议,以及摘录一些各种用于博客搭建的link. 在博客园3年6个月,确实也学到了很多,博客园也是目前为 ...

  3. Hexo 官方主题 landscape-plus 优化

    博主喜欢简洁大方的Hexo主题,看了不下100个主题之后,最终选择了 landscape-plus 主题(针对中国大陆地区,对Hexo官方主题landscape进行优化后的版本).更多Hexo主题资源 ...

  4. ICARUS主题美化

    Icarus用户指南 - 主题美化 Icarus的主题样式编码文件为themes/icarus/layout/layout.jsx. 此文件定义了站点全局的样式设置.本文详细介绍了本主题针对文章分类的 ...

  5. hexo next主题为博客添加分享功能

    title: hexo next主题为博客添加分享功能 date: 2018-01-06 20:20:02 tags: [hexo博客, 博客配置] categories: hexo next主题配置 ...

  6. ubuntu16.04主题美化和软件推荐

    前几天把ubuntu从15.10更新到了16.10,在网上看到有很多直接更新出问题的,正好赶上换SSD,于是采用全新安装,之前用ubuntu的时候装软件最让人头疼了,这回又得头疼一次了!! 索性把他记 ...

  7. Android源码浅析(二)——Ubuntu Root,Git,VMware Tools,安装输入法,主题美化,Dock,安装JDK和配置环境

    Android源码浅析(二)--Ubuntu Root,Git,VMware Tools,安装输入法,主题美化,Dock,安装JDK和配置环境 接着上篇,上片主要是介绍了一些安装工具的小知识点Andr ...

  8. Hexo next主题下添加天气插件

    最近在优化hexo 新搭建的博客,想给博客添加一个天气插件,奈何找了很久也没发现,好不容易发现一个天气插件 心知天气:https://www.seniverse.com/widget/get 运气不好 ...

  9. 开源介绍·新款简约、实用与大气的Hexo新主题:BMW

    这是一个简约.大气.实用的Hexo新主题:BMW

  10. Ubuntu 16.04 主题美化及常用软件安装

    一.主题美化 系统清理 系统更新: 安装完系统之后,需要更新一些补丁.Ctrl+Alt+T调出终端,执行一下代码: sudo apt-get update sudo apt-get upgrade 卸 ...

随机推荐

  1. kubernetes kubectl 命令自动补全

    yum install -y bash-completion source /usr/share/bash-completion/bash_completion source <(kubectl ...

  2. Node.js(五)学生管理CRUD

    npm init -y(初始化项目) npm install express(引入express) npx express-generator -e(自动生成模板.添加对 ejs 模板引擎的支持) n ...

  3. SpringBoot课程学习(一)

    @SpringBootTest指定测试的启动类 声明@SpringBootTest @Test注解 @Test 指定测试方法 @Order排序 一:先声明排序模式 @TestMethodOrder(M ...

  4. PHP全栈开发(一):CentOS 7 配置LAMP

    服务器CentOS7 IP地址:10.28.2.249 进行网络配置 可以使用ip address命令查看当前的网卡状态 两张网卡,一张lo网卡一张ens160网卡 Ens160这个网卡的配置文件为/ ...

  5. 洛谷P1719 最大加权矩形 (DP/二维前缀和)

    题目描述也没啥好说的,就是给你个你n*n的矩形(带权),求其中最大权值的子矩阵. 首先比较好想的就是二维前缀和,n<=120,所以可以用暴力. 1 #include<bits/stdc++ ...

  6. 撸了一个简易的配置中心,顺带整合到了SpringCloud

    大家好,我是三友~~ 最近突然心血来潮(就是闲的)就想着撸一个简单的配置中心,顺便也照葫芦画瓢给整合到SpringCloud. 本文大纲 配置中心的概述 随着历史的车轮不断的前进,技术不断的进步,单体 ...

  7. 驱动开发:内核枚举DpcTimer定时器

    在笔者上一篇文章<驱动开发:内核枚举IoTimer定时器>中我们通过IoInitializeTimer这个API函数为跳板,向下扫描特征码获取到了IopTimerQueueHead也就是I ...

  8. Windows应急响应——敬请期待!

    检查内容 进程.服务.用户.网络连接.漏洞补丁.木马查杀. 工具 火绒剑. 防护措施 杀毒软件

  9. JSP中使用response对象实现定时跳转网页

    5秒后跳转到登录页面 <% response.setHeader("refresh","5;URL="login.jsp"); %>

  10. Oracle性能优化之内存管理

    Oracle实例中的内存使用分为两类:程序全局区(program global area, PGA)和系统全局区(system global area, SGA).前者专门供每个会话使用,后者由所有O ...