PageSourceSearch

https://nakanomk.github.io/js/myJS.js

js nakanomk.github.io collected 2026-10-03 09:39:31 UTC 4,992 bytes, 147 lines download raw bytes

1// 标题栏
2var OriginTitle = document.title;
3var titleTime;
4document.addEventListener('visibilitychange', function () {
5	if (document.hidden) {
6		document.title = 'ヽ(●-`Д´-)ノ补药抛弃Nkns啊';
7		clearTimeout(titleTime);
8	}
9	else {
10		document.title = OriginTitle;
11		titleTime = setTimeout(function () {
12			document.title = OriginTitle;
13		}, 2000);
14	}
15});
16
17//下雪js
18/* 控制下雪 */
19function snowFall(snow) {
20	/* 可配置属性 */
21	snow = snow || {};
22	this.maxFlake = snow.maxFlake || 200;   /* 最多片数 */
23	this.flakeSize = snow.flakeSize || 10;  /* 雪花形状 */
24	this.fallSpeed = snow.fallSpeed || 1;   /* 坠落速度 */
25}
26/* 兼容写法 */
27requestAnimationFrame = window.requestAnimationFrame ||
28	window.mozRequestAnimationFrame ||
29	window.webkitRequestAnimationFrame ||
30	window.msRequestAnimationFrame ||
31	window.oRequestAnimationFrame ||
32	function (callback) { setTimeout(callback, 1000 / 60); };
33
34cancelAnimationFrame = window.cancelAnimationFrame ||
35	window.mozCancelAnimationFrame ||
36	window.webkitCancelAnimationFrame ||
37	window.msCancelAnimationFrame ||
38	window.oCancelAnimationFrame;
39/* 开始下雪 */
40snowFall.prototype.start = function () {
41	/* 创建画布 */
42	snowCanvas.apply(this);
43	/* 创建雪花形状 */
44	createFlakes.apply(this);
45	/* 画雪 */
46	drawSnow.apply(this)
47}
48/* 创建画布 */
49function snowCanvas() {
50	/* 添加Dom结点 */
51	var snowcanvas = document.createElement("canvas");
52	snowcanvas.id = "snowfall";
53	snowcanvas.width = document.body.clientWidth;
54	snowcanvas.height = document.body.clientHeight;
55		if(snowcanvas.height > 6000) {
56			snowcanvas.height = 6000;
57		}
58	snowcanvas.setAttribute("style", "position:absolute; top: 0; left: 0; z-index: 1; pointer-events: none;");
59	document.getElementsByTagName("body")[0].appendChild(snowcanvas);
60	this.canvas = snowcanvas;
61	this.ctx = snowcanvas.getContext("2d");
62	/* 窗口大小改变的处理 */
63	window.onresize = function () {
64		snowcanvas.width = window.innerWidth - 20;
65		/* snowcanvas.height = window.innerHeight */
66	}
67}
68/* 雪运动对象 */
69function flakeMove(canvasWidth, canvasHeight, flakeSize, fallSpeed) {
70	this.x = Math.floor(Math.random() * canvasWidth);   /* x坐标 */
71	this.y = Math.floor(Math.random() * canvasHeight);  /* y坐标 */
72	this.size = Math.random() * flakeSize + 2;          /* 形状 */
73	this.maxSize = flakeSize;                           /* 最大形状 */
74	this.speed = Math.random() * 1 + fallSpeed;         /* 坠落速度 */
75	this.fallSpeed = fallSpeed;                         /* 坠落速度 */
76	this.velY = this.speed;                             /* Y方向速度 */
77	this.velX = 0;                                      /* X方向速度 */
78	this.stepSize = Math.random() / 30;                 /* 步长 */
79	this.step = 0                                       /* 步数 */
80}
81flakeMove.prototype.update = function () {
82	var x = this.x,
83		y = this.y;
84	/* 左右摆动(余弦) */
85	this.velX *= 0.98;
86	if (this.velY <= this.speed) {
87		this.velY = this.speed
88	}
89	this.velX += Math.cos(this.step += .05) * this.stepSize;
90
91	this.y += this.velY;
92	this.x += this.velX;
93	/* 飞出边界的处理 */
94	if (this.x >= canvas.width || this.x <= 0 || this.y >= canvas.height || this.y <= 0) {
95		this.reset(canvas.width, canvas.height)
96	}
97};
98/* 飞出边界-放置最顶端继续坠落 */
99flakeMove.prototype.reset = function (width, height) {
100	this.x = Math.floor(Math.random() * width);
101	this.y = 0;
102	this.size = Math.random() * this.maxSize + 2;
103	this.speed = Math.random() * 1 + this.fallSpeed;
104	this.velY = this.speed;
105	this.velX = 0;
106};
107// 渲染雪花-随机形状(此处可修改雪花颜色!!!)
108flakeMove.prototype.render = function (ctx) {
109	var snowFlake = ctx.createRadialGradient(this.x, this.y, 0, this.x, this.y, this.size);
110	snowFlake.addColorStop(0, "rgba(255, 255, 255, 0.9)");  /* 此处是雪花颜色,默认是白色 */
111	snowFlake.addColorStop(.5, "rgba(255, 255, 255, 0.5)"); /* 若要改为其他颜色,请自行查 */
112	snowFlake.addColorStop(1, "rgba(255, 255, 255, 0)");    /* 找16进制的RGB 颜色代码。 */
113	ctx.save();
114	ctx.fillStyle = snowFlake;
115	ctx.beginPath();
116	ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
117	ctx.fill();
118	ctx.restore();
119};
120/* 创建雪花-定义形状 */
121function createFlakes() {
122	var maxFlake = this.maxFlake,
123		flakes = this.flakes = [],
124		canvas = this.canvas;
125	for (var i = 0; i < maxFlake; i++) {
126		flakes.push(new flakeMove(canvas.width, canvas.height, this.flakeSize, this.fallSpeed))
127	}
128}
129/* 画雪 */
130function drawSnow() {
131	var maxFlake = this.maxFlake,
132		flakes = this.flakes;
133	ctx = this.ctx, canvas = this.canvas, that = this;
134	/* 清空雪花 */
135	ctx.clearRect(0, 0, canvas.width, canvas.height);
136	for (var e = 0; e < maxFlake; e++) {
137		flakes[e].update();
138		flakes[e].render(ctx);
139	}
140	/*  一帧一帧的画 */
141	this.loop = requestAnimationFrame(function () {
142		drawSnow.apply(that);
143	});
144}
145/* 调用及控制方法 */
146var snow = new snowFall({ maxFlake: 60 });
147snow.start();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.