0%

hexo_next主题添加齿形雪花特效

介绍一下我正在使用的雪花特效,我也是抄的网上别的师傅博客😁😁😁

1.在\blog\themes\next\source\js目录创建一个文件snow.js,添加下面的代码:

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
(function ($) {
$.fn.snow = function (options) {
var $flake = $('<div id="snowbox" />').css({
'position': 'absolute',
'z-index': '9999',
'top': '-50px'
}).html('❄'),
documentHeight = $(document).height(),
documentWidth = $(document).width(),
defaults = {
minSize: 10,
maxSize: 20,
newOn: 1000,
flakeColor: "#AFDAEF" /* 此处可以定义雪花颜色,若要白色可以改为#FFFFFF */
},
options = $.extend({}, defaults, options);
var interval = setInterval(function () {
var startPositionLeft = Math.random() * documentWidth - 100,
startOpacity = 0.5 + Math.random(),
sizeFlake = options.minSize + Math.random() * options.maxSize,
endPositionTop = documentHeight - 200,
endPositionLeft = startPositionLeft - 500 + Math.random() * 500,
durationFall = documentHeight * 10 + Math.random() * 5000;
$flake.clone().appendTo('body').css({
left: startPositionLeft,
opacity: startOpacity,
'font-size': sizeFlake,
color: options.flakeColor
}).animate({
top: endPositionTop,
left: endPositionLeft,
opacity: 0.2
}, durationFall, 'linear', function () {
$(this).remove()
});
}, options.newOn);
};
})(jQuery);
$(function () {
$.fn.snow({
minSize: 5,
/* 定义雪花最小尺寸 */
maxSize: 50,
/* 定义雪花最大尺寸 */
newOn: 300 /* 定义密集程度,数字越小越密集 */
});
});

2.在\blog\themes\next\layout\_layout.swig写入:

1
2
<!-- 引入jQuery -->
<script type="text/javascript" src="//libs.baidu.com/jquery/1.8.3/jquery.min.js"></script>

如果已经引入jQuery,可以忽略此步

3.然后还是在这个文件\blog\themes\next\layout\_layout.swig中添加代码:

1
2
<!-- 雪花特效 -->
<script type="text/javascript" src="/js/snow.js"></script>

第三步写入的代码一定要在第二步代码的后面,如下图所示:

图片

4.在\blog\themes\next\_config.yml中添加下面代码:

1
2
3
# 雪花特效
snow2:
enabled: true

参考文章:https://blog.csdn.net/QFREX/article/details/108798945