这位怪蜀黍 中午的时光真难熬!还好有你在!

博客美化,页脚游动的鱼

首先需要开通博客js权限

接着在博客页脚html栏添加如下代码,就OK

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<div id="datouwang" class="container1"></div>
 
<script>
var RENDERER = {
    POINT_INTERVAL : 5,
    FISH_COUNT : 2,
    MAX_INTERVAL_COUNT : 50,
    INIT_HEIGHT_RATE : 0.5,
     
    init : function(){
        this.setParameters();
        this.reconstructMethods();
        this.setup();
        this.bindEvent();
        this.render();
    },
    setParameters : function(){
        this.$window = $(window);
        this.$container = $('#datouwang');
        this.$canvas = $('<canvas />');
        this.context = this.$canvas.appendTo(this.$container).get(0).getContext('2d');
        this.points = [];
        this.fishes = [];
        this.watchIds = [];
    },
    createSurfacePoints : function(){
        var count = Math.round(this.width / this.POINT_INTERVAL);
        this.pointInterval = this.width / (count - 1);
        this.points.push(new SURFACE_POINT(this, 0));
         
        for(var i = 1; i < count; i++){
            var point = new SURFACE_POINT(this, i * this.pointInterval),
                previous = this.points[i - 1];
                 
            point.setPreviousPoint(previous);
            previous.setNextPoint(point);
            this.points.push(point);
        }
    },
    reconstructMethods : function(){
        this.watchWindowSize = this.watchWindowSize.bind(this);
        this.jdugeToStopResize = this.jdugeToStopResize.bind(this);
        this.startEpicenter = this.startEpicenter.bind(this);
        this.moveEpicenter = this.moveEpicenter.bind(this);
        this.render = this.render.bind(this);
    },
    setup : function(){
        this.points.length = 0;
        this.fishes.length = 0;
        this.watchIds.length = 0;
        this.intervalCount = this.MAX_INTERVAL_COUNT;
        this.width = this.$container.width();
        this.height = this.$container.height();
        this.fishCount = this.FISH_COUNT * this.width / 500 * this.height / 500;
        this.$canvas.attr({width : this.width, height : this.height});
         
        this.skyGradient = this.context.createLinearGradient(0, 0, 0, this.height);
        this.skyGradient.addColorStop(0, 'hsl(180, 80%, 90%)');
        this.skyGradient.addColorStop(1, 'hsl(180, 80%, 60%)');
         
        this.seaGradient = this.context.createLinearGradient(0, 0, 0, this.height);
        this.seaGradient.addColorStop(0, 'hsl(180, 80%, 60%)');
        this.seaGradient.addColorStop(0.5, 'hsl(180, 80%, 50%)');
        this.seaGradient.addColorStop(1, 'hsl(210, 80%, 50%)');
         
        this.fishes.push(new FISH(this));
        this.createSurfacePoints();
    },
    watchWindowSize : function(){
        this.clearTimer();
        this.tmpWidth = this.$window.width();
        this.tmpHeight = this.$window.height();
        this.watchIds.push(setTimeout(this.jdugeToStopResize, this.WATCH_INTERVAL));
    },
    clearTimer : function(){
        while(this.watchIds.length > 0){
            clearTimeout(this.watchIds.pop());
        }
    },
    jdugeToStopResize : function(){
        var width = this.$window.width(),
            height = this.$window.height(),
            stopped = (width == this.tmpWidth && height == this.tmpHeight);
             
        this.tmpWidth = width;
        this.tmpHeight = height;
         
        if(stopped){
            this.setup();
        }
    },
    bindEvent : function(){
        this.$window.on('resize', this.watchWindowSize);
        this.$container.on('mouseenter', this.startEpicenter);
        this.$container.on('mousemove', this.moveEpicenter);
    },
    getAxis : function(event){
        var offset = this.$container.offset();
         
        return {
            x : event.clientX - offset.left + this.$window.scrollLeft(),
            y : event.clientY - offset.top + this.$window.scrollTop()
        };
    },
    startEpicenter : function(event){
        this.axis = this.getAxis(event);
    },
    moveEpicenter : function(event){
        var axis = this.getAxis(event);
         
        if(!this.axis){
            this.axis = axis;
        }
        this.points[Math.round(axis.x / this.pointInterval)].interfere(axis.y, axis.y - this.axis.y);
        this.axis = axis;
    },
    generateEpicenter : function(x, y, prevX, prevY){
        var index = Math.round(x / this.pointInterval);
         
        if(index < 0 || index >= this.points.length){
            return;
        }
        this.points[index].interfere(y, y - prevY);
    },
    render : function(){
        requestAnimationFrame(this.render);
        this.context.fillStyle = this.skyGradient;
        this.context.fillRect(0, 0, this.width, this.height);
        this.context.fillStyle = this.seaGradient;
        this.context.beginPath();
        this.context.moveTo(0, this.height);
         
        for(var i = 0, count = this.points.length; i < count; i++){
            this.points[i].updateSelf();
        }
        for(var i = 0, count = this.points.length; i < count; i++){
            this.points[i].updateNeighbors();
        }
        for(var i = 0, count = this.points.length; i < count; i++){
            this.points[i].render(this.context);
        }
        this.context.lineTo(this.width, this.height);
        this.context.closePath();
        this.context.fill();
         
        for(var i = 0, count = this.fishes.length; i < count; i++){
            this.fishes[i].render(this.context);
        }
        if(this.fishes.length < this.fishCount){
            if(--this.intervalCount == 0){
                this.intervalCount = this.MAX_INTERVAL_COUNT;
                this.fishes.push(new FISH(this));
            }
        }
    }
};
var SURFACE_POINT = function(renderer, x){
    this.renderer = renderer;
    this.x = x;
    this.init();
};
SURFACE_POINT.prototype = {
    SPRING_CONSTANT : 0.03,
    SPRING_FRICTION : 0.9,
    WAVE_SPREAD : 0.3,
    ACCELARATION_RATE : 0.01,
     
    init : function(){
        this.initHeight = this.renderer.height * this.renderer.INIT_HEIGHT_RATE;
        this.height = this.initHeight;
        this.fy = 0;
        this.force = {previous : 0, next : 0};
    },
    setPreviousPoint : function(previous){
        this.previous = previous;
    },
    setNextPoint : function(next){
        this.next = next;
    },
    interfere : function(y, velocity){
        var offset = this.renderer.height - this.height - y;
         
        if(offset > 0 && velocity < 0 || offset < 0 && velocity > 0){
            return;
        }
        this.fy = this.renderer.height * this.ACCELARATION_RATE * (offset >= 0 ? -1 : 1) * Math.abs(velocity);
    },
    updateSelf : function(){
        this.fy += this.SPRING_CONSTANT * (this.initHeight - this.height);
        this.fy *= this.SPRING_FRICTION;
        this.height += this.fy;
    },
    updateNeighbors : function(){
        if(this.previous){
            this.force.previous = this.WAVE_SPREAD * (this.height - this.previous.height);
        }
        if(this.next){
            this.force.next = this.WAVE_SPREAD * (this.height - this.next.height);
        }
    },
    render : function(context){
        if(this.previous){
            this.previous.height += this.force.previous;
            this.previous.fy += this.force.previous;
        }
        if(this.next){
            this.next.height += this.force.next;
            this.next.fy += this.force.next;
        }
        context.lineTo(this.x, this.renderer.height - this.height);
    }
};
var FISH = function(renderer){
    this.renderer = renderer;
    this.init();
};
FISH.prototype = {
    LENGTH : 40,
    GRAVITY : 0.4,
     
    init : function(){
        this.direction = Math.random() < 0.5;
        this.x = this.direction ? (this.renderer.width + this.LENGTH) : -this.LENGTH;
        this.y = this.getRandomValue(this.renderer.height * 6 / 10, this.renderer.height * 9 / 10);
        this.prevX = this.x;
        this.prevY = this.y;
        this.vx = this.getRandomValue(4, 8) * (this.direction ? -1 : 1);
        this.vy = this.getRandomValue(-5, -2);
        this.ay = this.getRandomValue(-0.2, -0.05);
        this.theta = 0;
        this.phi = 0;
        this.isOut = false;
    },
    getRandomValue : function(min, max){
        return min + (max - min) * Math.random();
    },
    render : function(context){
        context.save();
        context.translate(this.x, this.y);
        context.rotate(Math.PI + Math.atan2(this.vy, this.vx));
        context.scale(1, this.direction ? 1 : -1);
         
        context.fillStyle = 'hsl(180, 30%, 80%)';
        context.beginPath();
        context.moveTo(-30, 0);
        context.bezierCurveTo(-20, 15, 15, 10, 40, 0);
        context.bezierCurveTo(15, -10, -20, -15, -30, 0);
        context.fill();
         
        context.save();
        context.translate(40, 0);
        context.scale(0.9 + 0.1 * Math.sin(this.theta), 1);
        context.fillStyle = 'hsl(180, 30%, 80%)';
        context.beginPath();
        context.moveTo(0, 0);
        context.quadraticCurveTo(5, 10, 20, 8);
        context.quadraticCurveTo(12, 5, 10, 0);
        context.quadraticCurveTo(12, -5, 20, -8);
        context.quadraticCurveTo(5, -10, 0, 0);
        context.fill();
        context.restore();
         
        context.save();
        context.translate(-3, 0);
        context.rotate(Math.PI / 3 + Math.PI / 20 * Math.sin(this.phi));
        context.fillStyle = 'hsl(220, 80%, 40%)';
        context.beginPath();
        context.moveTo(-5, 0);
        context.bezierCurveTo(-10, -10, -10, -30, 0, -40);
        context.bezierCurveTo(12, -25, 8, -10, 0, 0);
        context.closePath();
        context.fill();
        context.restore();
         
        context.strokeStyle = 'hsl(220, 80%, 40%)';
        context.beginPath();
        context.arc(-15, -3, 5, 0, Math.PI * 2, false);
        context.stroke();
         
        context.fillStyle = 'hsl(220, 80%, 40%)';
        context.beginPath();
        context.arc(-15, -3, 3, 0, Math.PI * 2, false);
        context.fill();
         
        context.restore();
         
        this.prevX = this.x;
        this.prevY = this.y;
         
        this.x += this.vx;
        this.y += this.vy;
         
        this.vy += this.ay;
         
        if(this.y < this.renderer.height * this.renderer.INIT_HEIGHT_RATE){
            this.vy += this.GRAVITY;
            this.isOut = true;
        }else{
            if(this.isOut){
                this.ay = this.getRandomValue(-0.2, -0.05);
            }
            this.isOut = false;
        }
        this.theta += Math.PI / 20;
        this.theta %= Math.PI * 2;
        this.phi += Math.PI / 30;
        this.theta %= Math.PI * 2;
         
        if(this.y > this.renderer.height * this.renderer.INIT_HEIGHT_RATE - this.LENGTH && this.y < this.renderer.height * this.renderer.INIT_HEIGHT_RATE + this.LENGTH){
            this.renderer.generateEpicenter(this.x + (this.direction ? -1 : 1) * this.LENGTH, this.y, this.prevX, this.prevY);
        }
        if(this.vx > 0 && this.x > this.renderer.width + this.LENGTH || this.vx < 0 && this.x < -this.LENGTH){
            this.init();
        }
    }
};
$(function(){
    RENDERER.init();
});
 
</script>

 页面定制的CSS样式如下

1
2
3
4
5
6
7
8
9
10
.container1{
        width: 100%;
        height:400px;
        margin: 0;
        padding: 0;
        background-color:#FFFFFF;
        float:left;
        margin-top:-400px;
        opacity:0.1;
}

  

posted @   蟾宝  阅读(110)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示