js蜘蛛网更随鼠标特效

代码

 1 <script>
 2   !
 3   function() {
 4       function n(n, e, t) {
 5           return n.getAttribute(e) || t
 6       }
 7       function e(n) {
 8           return document.getElementsByTagName(n)
 9       }
10       function t() {
11           var t = e("script"),
12           o = t.length,
13           i = t[o - 1];
14           return {
15               l: o,
16               z: n(i, "zIndex", -1),
17               o: n(i, "opacity", .9),   //透明度
18               c: n(i, "color", "255, 102, 153"),   //颜色
19               n: n(i, "count", 99)
20           }
21       }
22       function o() {
23           a = m.width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
24           c = m.height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
25       }
26       function i() {
27           r.clearRect(0, 0, a, c);
28           var n, e, t, o, m, l;
29           s.forEach(function(i, x) {
30               for (i.x += i.xa, i.y += i.ya, i.xa *= i.x > a || i.x < 0 ? -1 : 1, i.ya *= i.y > c || i.y < 0 ? -1 : 1, r.fillRect(i.x - .5, i.y - .5, 1, 1), e = x + 1; e < u.length; e++) n = u[e],
31               null !== n.x && null !== n.y && (o = i.x - n.x, m = i.y - n.y, l = o * o + m * m, l < n.max && (n === y && l >= n.max / 2 && (i.x -= .03 * o, i.y -= .03 * m), t = (n.max - l) / n.max, r.beginPath(), r.lineWidth = t / 2, r.strokeStyle = "rgba(" + d.c + "," + (t + .2) + ")", r.moveTo(i.x, i.y), r.lineTo(n.x, n.y), r.stroke()))
32           }),
33           x(i)
34       }
35       var a, c, u, m = document.createElement("canvas"),
36       d = t(),
37       l = "c_n" + d.l,
38       r = m.getContext("2d"),
39       x = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
40       function(n) {
41           window.setTimeout(n, 1e3 / 45)
42       },
43       w = Math.random,
44       y = {
45           x: null,
46           y: null,
47           max: 2e4
48       };
49       m.id = l,
50       m.style.cssText = "position:fixed;top:0;left:0;z-index:" + d.z + ";opacity:" + d.o,
51       e("body")[0].appendChild(m),
52       o(),
53       window.onresize = o,
54       window.onmousemove = function(n) {
55           n = n || window.event,
56           y.x = n.clientX,
57           y.y = n.clientY
58       },
59       window.onmouseout = function() {
60           y.x = null,
61           y.y = null
62       };
63       for (var s = [], f = 0; d.n > f; f++) {
64           var h = w() * a,
65           g = w() * c,
66           v = 2 * w() - 1,
67           p = 2 * w() - 1;
68           s.push({
69               x: h,
70               y: g,
71               xa: v,
72               ya: p,
73               max: 6e3
74           })
75       }
76       u = s.concat([y]),
77       setTimeout(function() {
78           i()
79       },
80       100)
81   } ();
82   </script>
View Code

猜你喜欢

转载自www.cnblogs.com/zwnsyw/p/12297581.html
今日推荐