服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - 编程技术 - html5跟随鼠标炫酷动画欢迎页hovertreewelcome

html5跟随鼠标炫酷动画欢迎页hovertreewelcome

2023-05-30 11:25zjy 编程技术

原生js与html5实现的跟随鼠标炫酷动画欢迎页,刚好今天看到了就分享给大家

 html5跟随鼠标炫酷网站引导页动画特效一款非常不错的引导页,文字效果渐变,鼠标跟随出绚丽的条纹。html5炫酷网站引导页,鼠标跟随出特效。

效果图

html5跟随鼠标炫酷动画欢迎页hovertreewelcome

index.htm

?
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<!DOCTYPE html>
<html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>
            黑页
        </title>
 
        <style>
            body{
                font: 500 .875em PingFang SC,Lantinghei SC,Microsoft Yahei,Hiragino Sans GB,Microsoft Sans Serif,WenQuanYi Micro Hei,sans;
                background-color: #07040e;
            }
            #canvas {
                position: absolute;
                z-index: -1;
                top: 0;
                left: 0;
                bottom: 0;
                right: 0;
                cursor: none;
            }
        </style>
 
 
    </head>
    <body>
        <canvas id="canvas" width="100%" height="100%"></canvas>
        <script src="hovertreewelcome.js"></script>
        <script type="text/javascript">
            (function(window) {
 
                var ctx,
                    hue,
                    logo,
                    form,
                    buffer,
                    target = {},
                    tendrils = [],
                    settings = {};
 
                settings.debug = true;
                settings.friction = 0.5;
                settings.trails = 20;
                settings.size = 50;
                settings.dampening = 0.25;
                settings.tension = 0.98;
 
                Math.TWO_PI = Math.PI * 2;
 
                // ========================================================================================
                // Oscillator 何问起
                // ----------------------------------------------------------------------------------------
 
                function Oscillator(options) {
                    this.init(options || {});
                }
 
                Oscillator.prototype = (function() {
 
                    var value = 0;
 
                    return {
 
                        init: function(options) {
                            this.phase = options.phase || 0;
                            this.offset = options.offset || 0;
                            this.frequency = options.frequency || 0.001;
                            this.amplitude = options.amplitude || 1;
                        },
 
                        update: function() {
                            this.phase += this.frequency;
                            value = this.offset + Math.sin(this.phase) * this.amplitude;
                            return value;
                        },
 
                        value: function() {
                            return value;
                        }
                    };
 
                })();
 
 
                function Tendril(options) {
                    this.init(options || {});
                }
 
                Tendril.prototype = (function() {
 
                    function Node() {
                        this.x = 0;
                        this.y = 0;
                        this.vy = 0;
                        this.vx = 0;
                    }
 
                    return {
 
                        init: function(options) {
 
                            this.spring = options.spring + (Math.random() * 0.1) - 0.05;
                            this.friction = settings.friction + (Math.random() * 0.01) - 0.005;
                            this.nodes = [];
 
                            for (var i = 0, node; i < settings.size; i++) {
 
                                node = new Node();
                                node.x = target.x;
                                node.y = target.y;
 
                                this.nodes.push(node);
                            }
                        },
 
                        update: function() {
 
                            var spring = this.spring,
                                node = this.nodes[0];
 
                            node.vx += (target.x - node.x) * spring;
                            node.vy += (target.y - node.y) * spring;
 
                            for (var prev, i = 0, n = this.nodes.length; i < n; i++) {
 
                                node = this.nodes[i];
 
                                if (i > 0) {
 
                                    prev = this.nodes[i - 1];
 
                                    node.vx += (prev.x - node.x) * spring;
                                    node.vy += (prev.y - node.y) * spring;
                                    node.vx += prev.vx * settings.dampening;
                                    node.vy += prev.vy * settings.dampening;
                                }
 
                                node.vx *= this.friction;
                                node.vy *= this.friction;
                                node.x += node.vx;
                                node.y += node.vy;
 
                                spring *= settings.tension;
                            }
                        },
 
                        draw: function() {
 
                            var x = this.nodes[0].x,
                                y = this.nodes[0].y,
                                a, b;
 
                            ctx.beginPath();
                            ctx.moveTo(x, y);
 
                            for (var i = 1, n = this.nodes.length - 2; i < n; i++) {
 
                                a = this.nodes[i];
                                b = this.nodes[i + 1];
                                x = (a.x + b.x) * 0.5;
                                y = (a.y + b.y) * 0.5;
 
                                ctx.quadraticCurveTo(a.x, a.y, x, y);
                            }
 
                            a = this.nodes[i];
                            b = this.nodes[i + 1];
 
                            ctx.quadraticCurveTo(a.x, a.y, b.x, b.y);
                            ctx.stroke();
                            ctx.closePath();
                        }
                    };
 
                })();
 
                // ----------------------------------------------------------------------------------------
 
                function init(event) {
 
                    document.removeEventListener('mousemove', init);
                    document.removeEventListener('touchstart', init);
 
                    document.addEventListener('mousemove', mousemove);
                    document.addEventListener('touchmove', mousemove);
                    document.addEventListener('touchstart', touchstart);
 
                    mousemove(event);
                    reset();
                    loop();
                }
 
                function reset() {
 
                    tendrils = [];
 
                    for (var i = 0; i < settings.trails; i++) {
 
                        tendrils.push(new Tendril({
                            spring: 0.45 + 0.025 * (i / settings.trails)
                        }));
                    }
                }
 
                function loop() {
 
                    if (!ctx.running) return;
 
                    ctx.globalCompositeOperation = 'source-over';
                    ctx.fillStyle = 'rgba(8,5,16,0.4)';
                    ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
                    ctx.globalCompositeOperation = 'lighter';
                    ctx.strokeStyle = 'hsla(' + Math.round(hue.update()) + ',90%,50%,0.25)';
                    ctx.lineWidth = 1;
 
                    if (ctx.frame % 60 == 0) {
                        console.log(hue.update(), Math.round(hue.update()), hue.phase, hue.offset, hue.frequency, hue.amplitude);
                    }
 
                    for (var i = 0, tendril; i < settings.trails; i++) {
                        tendril = tendrils[i];
                        tendril.update();
                        tendril.draw();
                    }
 
                    ctx.frame++;
                    ctx.stats.update();
                    requestAnimFrame(loop);
                }
 
                function resize() {
                    ctx.canvas.width = window.innerWidth;
                    ctx.canvas.height = window.innerHeight;
                }
 
                function start() {
                    if (!ctx.running) {
                        ctx.running = true;
                        loop();
                    }
                }
 
                function stop() {
                    ctx.running = false;
                }
 
                function mousemove(event) {
                    if (event.touches) {
                        target.x = event.touches[0].pageX;
                        target.y = event.touches[0].pageY;
                    } else {
                        target.x = event.clientX
                        target.y = event.clientY;
                    }
                    event.preventDefault();
                }
 
                function touchstart(event) {
                    if (event.touches.length == 1) {
                        target.x = event.touches[0].pageX;
                        target.y = event.touches[0].pageY;
                    }
                }
 
                function keyup(event) {
 
                    switch (event.keyCode) {
                        case 32:
                            save();
                            break;
                        default:
                            // console.log(event.keyCode); hovertree.com
                    }
                }
 
                function letters(id) {
 
                    var el = document.getElementById(id),
                        letters = el.innerHTML.replace('&amp;', '&').split(''),
                        heading = '';
 
                    for (var i = 0, n = letters.length, letter; i < n; i++) {
                        letter = letters[i].replace('&', '&amp');
                        heading += letter.trim() ? '<span class="letter-' + i + '">' + letter + '</span>' : '&nbsp;';
                    }
 
                    el.innerHTML = heading;
                    setTimeout(function() {
                        el.className = 'transition-in';
                    }, (Math.random() * 500) + 500);
                }
 
                function save() {
 
                    if (!buffer) {
 
                        buffer = document.createElement('canvas');
                        buffer.width = screen.availWidth;
                        buffer.height = screen.availHeight;
                        buffer.ctx = buffer.getContext('2d');
 
                        form = document.createElement('form');
                        form.method = 'post';
                        form.input = document.createElement('input');
                        form.input.type = 'hidden';
                        form.input.name = 'data';
                        form.appendChild(form.input);
 
                        document.body.appendChild(form);
                    }
 
                    buffer.ctx.fillStyle = 'rgba(8,5,16)';
                    buffer.ctx.fillRect(0, 0, buffer.width, buffer.height);
 
                    buffer.ctx.drawImage(canvas,
                        Math.round(buffer.width / 2 - canvas.width / 2),
                        Math.round(buffer.height / 2 - canvas.height / 2)
                    );
 
                    buffer.ctx.drawImage(logo,
                        Math.round(buffer.width / 2 - logo.width / 4),
                        Math.round(buffer.height / 2 - logo.height / 4),
                        logo.width / 2,
                        logo.height / 2
                    );
 
                    window.open(buffer.toDataURL(), 'wallpaper', 'top=0,left=0,width=' + buffer.width + ',height=' + buffer.height);
 
                    // form.input.value = buffer.toDataURL().substr(22);
                    // form.submit(); hovertree.com
                }
 
                window.requestAnimFrame = (function() {
                    return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame ||
                        function(fn) {
                            window.setTimeout(fn, 1000 / 60)
                        };
                })();
 
                window.onload = function() {
 
                    ctx = document.getElementById('canvas').getContext('2d');
                    ctx.stats = new Stats();
                    ctx.running = true;
                    ctx.frame = 1;
 
 
 
                    hue = new Oscillator({
                        phase: Math.random() * Math.TWO_PI,
                        amplitude: 85,
                        frequency: 0.0015,
                        offset: 285
                    });
 
 
 
                    document.addEventListener('mousemove', init);
                    document.addEventListener('touchstart', init);
                    document.body.addEventListener('orientationchange', resize);
                    window.addEventListener('resize', resize);
                    window.addEventListener('keyup', keyup);
                    window.addEventListener('focus', start);
                    window.addEventListener('blur', stop);
 
                    resize();
 
                    if (window.DEBUG) {
 
                        var gui = new dat.GUI();
 
                        // gui.add(settings, 'debug');
                        settings.gui.add(settings, 'trails', 1, 30).onChange(reset);
                        settings.gui.add(settings, 'size', 25, 75).onFinishChange(reset);
                        settings.gui.add(settings, 'friction', 0.45, 0.55).onFinishChange(reset);
                        settings.gui.add(settings, 'dampening', 0.01, 0.4).onFinishChange(reset);
                        settings.gui.add(settings, 'tension', 0.95, 0.999).onFinishChange(reset);
 
                        document.body.appendChild(ctx.stats.domElement);
                    }
                };
 
            })(window);
        </script>
 
    </body>
</html>

hovertreewelcome.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
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
var Stats = function() {
    var e = Date.now(),
        t = e,
        i = 0,
        n = 1 / 0,
        r = 0,
        s = 0,
        o = 1 / 0,
        a = 0,
        l = 0,
        h = 0,
        c = document.createElement("div");
    c.id = "stats", c.addEventListener("mousedown", function(e) {
        e.preventDefault(), v(++h % 2)
    }, !1), c.style.cssText = "width:80px;opacity:0.9;cursor:pointer";
    var u = document.createElement("div");
    u.id = "fps", u.style.cssText = "padding:0 0 3px 3px;text-align:left;background-color:#002", c.appendChild(u);
    var d = document.createElement("div");
    d.id = "fpsText", d.style.cssText =
        "color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px", d.innerHTML =
        "FPS", u.appendChild(d);
    var p = document.createElement("div");
    for (p.id = "fpsGraph", p.style.cssText = "position:relative;width:74px;height:30px;background-color:#0ff", u.appendChild(
            p); 74 > p.children.length;) {
        var f = document.createElement("span");
        f.style.cssText = "width:1px;height:30px;float:left;background-color:#113", p.appendChild(f)
    }
    var m = document.createElement("div");
    m.id = "ms", m.style.cssText = "padding:0 0 3px 3px;text-align:left;background-color:#020;display:none", c.appendChild(
        m);
    var g = document.createElement("div");
    g.id = "msText", g.style.cssText =
        "color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px", g.innerHTML =
        "MS", m.appendChild(g);
    var y = document.createElement("div");
    for (y.id = "msGraph", y.style.cssText = "position:relative;width:74px;height:30px;background-color:#0f0", m.appendChild(
            y); 74 > y.children.length;) {
        var f = document.createElement("span");
        f.style.cssText = "width:1px;height:30px;float:left;background-color:#131", y.appendChild(f)
    }
    var v = function(e) {
            switch (h = e) {
                case 0:
                    u.style.display = "block", m.style.display = "none";
                    break;
                case 1:
                    u.style.display = "none", m.style.display = "block"
            }
        },
        b = function(e, t) {
            var i = e.appendChild(e.firstChild);
            i.style.height = t + "px"
        };
    return {
        REVISION: 11,
        domElement: c,
        setMode: v,
        begin: function() {
            e = Date.now()
        },
        end: function() {
            var h = Date.now();
            return i = h - e, n = Math.min(n, i), r = Math.max(r, i), g.textContent = i + " MS (" + n + "-" + r + ")", b(y,
                Math.min(30, 30 - 30 * (i / 200))), l++, h > t + 1e3 && (s = Math.round(1e3 * l / (h - t)), o = Math.min(o, s),
                a = Math.max(a, s), d.textContent = s + " FPS (" + o + "-" + a + ")", b(p, Math.min(30, 30 - 30 * (s / 100))), t =
                h, l = 0), h
        },
        update: function() {
            e = this.end()
        }
    }
};

到此这篇关于html5跟随鼠标炫酷动画欢迎页hovertreewelcome的文章就介绍到这了,更多相关跟随鼠标炫酷动画效果内容请搜索服务器之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持服务器之家!

延伸 · 阅读

精彩推荐