代码: 复制代码 代码如下: http://www.w3.org/1999/xhtml"> jQuery实现炫酷的鼠标轨迹特效 window.onload = function () {<br /> C = Math.cos; S = Math.sin; U = 0; w = window; j = document; d = j.getElementById("kele"+"yi_com"); c = d.getContext("2d"); W = d.width = w.innerWidth; H = d.height = w.innerHeight; c.fillRect(0, 0, W, H); c.globalCompositeOperation = "lighter"; c.lineWidth = 0.2; c.lineCap = "round"; var bool = 0, t = 0; d.onmousemove = function (e) {<br /> if (window.T) {<br /> if (D == 9) { D = Math.random() * 15; f(1); }<br /> clearTimeout(T);<br /> }<br /> X = e.pageX; Y = e.pageY; a = 0; b = 0; A = X, B = Y; R = (e.pageX / W * 999 >> 0) / 999; r = (e.pageY / H * 999 >> 0) / 999; U = e.pageX / H * 360 >> 0; D = 9; g = 360 * Math.PI / 180; T = setInterval(f = function (e) {<br /> c.save(); c.globalCompositeOperation = "source-over"; if (e != 1) { c.fillStyle = "rgba(0,0,0,0.02)"; c.fillRect(0, 0, W, H); }<br /> c.restore(); i = 25; while (i--) {<br /> c.beginPath(); if (D > 450 || bool) {<br /> if (!bool) { bool = 1; }<br /> if (D < 0.1) { bool = 0; }<br /> t -= g; D -= 0.1;<br /> }<br /> if (!bool) { t += g; D += 0.1; }<br /> q = (R / r - 1) * t; x = (R - r) * C(t) + D * C(q) + (A + (X - A) * (i / 25)) + (r - R); y = (R - r) * S(t) - D * S(q) + (B + (Y - B) * (i / 25)); if (a) { c.moveTo(a, b); c.lineTo(x, y) }<br /> c.strokeStyle = "hsla(" + (U % 360) + ",100%,50%,0.75)"; c.stroke(); a = x; b = y;<br /> }<br /> U -= 0.5; A = X; B = Y;<br /> }, 16);<br /> }<br /> j.onkeydown = function (e) { a = b = 0; R += 0.05 }<br /> d.onmousemove({ pageX: 300, pageY: 290 })<br /> } body{margin:0;overflow:hidden}div{padding:1px 5px;background:#333;position:absolute;z-index:2;color:#555;font-family:arial}a{color:#ccf}a:hover{color:red} 以上就是本文的内容了,希望小伙伴们喜欢此特效,快过年了,给自己的个人主页增添些色彩吧。