日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

炫酷线条背景动画

發布時間:2025/3/12 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 炫酷线条背景动画 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用H5的Canvas實現網頁的炫酷線條背景特效。

效果演示

代碼展示

html內容

<!DOCTYPE html> <html > <head> <meta charset="UTF-8"> <title></title><style> canvas{position:absolute;top:0;left:0;background-color:black; } </style></head> <body><canvas id=c></canvas><script src="js/style.js"></script><div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';"> </div> </body> </html>

js內容

var w = c.width = window.innerWidth,h = c.height = window.innerHeight,ctx = c.getContext('2d'),count = (w*h/3000)|0,speed = 4,range = 80,lineAlpha = .05,particles = [],huePart = 360/count;for(var i = 0; i < count; ++i)particles.push(new Particle((huePart*i)|0));function Particle(hue){this.x = Math.random()*w;this.y = Math.random()*h;this.vx = (Math.random()-.5)*speed;this.vy = (Math.random()-.5)*speed;this.hue = hue; } Particle.prototype.update = function(){this.x += this.vx;this.y += this.vy;if(this.x < 0 || this.x > w) this.vx *= -1;if(this.y < 0 || this.y > h) this.vy *= -1; }function checkDist(a, b, dist){var x = a.x - b.x,y = a.y - b.y;return x*x + y*y <= dist*dist; }function anim(){window.requestAnimationFrame(anim);ctx.fillStyle = 'rgba(0, 0, 0, .05)';ctx.fillRect(0, 0, w, h);for(var i = 0; i < particles.length; ++i){var p1 = particles[i];p1.update();for(var j = i+1; j < particles.length; ++j){var p2 = particles[j];if(checkDist(p1, p2, range)){ctx.strokeStyle = 'hsla(hue, 80%, 50%, alp)'.replace('hue', ((p1.hue + p2.hue + 3)/2) % 360).replace('alp', lineAlpha);ctx.beginPath();ctx.moveTo(p1.x, p1.y);ctx.lineTo(p2.x, p2.y);ctx.stroke();}}} }anim();

總結

以上是生活随笔為你收集整理的炫酷线条背景动画的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。