css3+HTML5 Canvas酷炫3D線條延伸動畫特效
js程式碼
<腳本> ;(功能() { '使用嚴格'; var c = document.getElementById('c'); var ctx = c.getContext('2d'); var w = c.width = window.innerWidth; var h = c.height = window.innerHeight; var cx = w / 2; var cy = h / 2; var fl = 1000; 函數 prj(obj) { var cz = obj.z + fl; 如果(cz === 0)返回; var scl = fl / cz; obj.p.x = cx + obj.x * scl; obj.p.y = cy + obj.y * scl; obj.s = scl; } var P = 函數(x, y, z) { 這個.x = x; 這個.y = y; 這個.z = z; 這個.s = 1; 這個.cl = 0; 這個.p = { x:0, y:0 }; }; P.原型 = { 構造函數:P, 更新:函數(){ 這個.z -= 30; }, 渲染:函數(ctx){ if(this.z <= -fl) 返回; ctx.save(); ctx.translate(this.p.x, this.p.y); ctx.scale(這個.s,這個.s); ctx.fillStyle = 'hsla(' + this.cl + ', 100%, 50%, 0.5)'; ctx.beginPath(); ctx.arc(0, 0, 2, 0, Math.PI * 2); ctx.fill(); ctx.restore(); } }; var M = 函數(x, y, z) { this.list = []; 這個.max = 100; 這個.x = x; 這個.y = y; 這個.z = z; 這個.s = 1; 這個.p = { x:0, y:0 }; this.ax = Math.random() * (Math.PI * 2); this.ay = Math.random() * (Math.PI * 2); this.rx = Math.random() * 100; this.ry = Math.random() * 100; this.cl = Math.random() * 360; this.cls = Math.random(); }; M.原型 = { 建構函數:M, 更新:函數(){ 這個.cl += 這個.cls; this.ax += Math.random() * 0.1 - 0.02; this.ay += Math.random() * 0.1 - 0.02; this.x = Math.cos(this.ax) * 100; this.y = Math.sin(this.ay) * 100; 這個.z += 10; if(this.z > fl) this.z = fl; if(this.list.length < this.max) { if(Math.random() * 100 < 50) { var pp = new P(this.x, this.y, this.z); pp.cl = this.cl; this.list.push(pp); } } 別的 { var pp = this.list.shift(); pp.x = this.x; pp.y = this.y; pp.z = this.z; pp.cl = this.cl; this.list.push(pp); } }, 渲染:函數(ctx){ if(this.z <= -fl) 返回; ctx.save(); ctx.translate(this.p.x, this.p.y); ctx.fillStyle = '綠色'; ctx.beginPath(); ctx.arc(0, 0, 2, 0, Math.PI * 2); ctx.fill(); ctx.restore(); } }; 函數更新(mv,列表){ for(var i = 0; i < list.length; i++) { var p = 列表[i]; p.update(); prj(p); p.渲染(ctx); } for(var i = list.length-1; i >= 0; i--) { var p = 列表[i]; if(p.z <= -fl) 繼續; if(i === 列表.length - 1) { ctx.lineWidth = Math.random(); ctx.StrongStyle = 'hsl(' + mv.cl + ', 100%, 50%)'; ctx.beginPath(); ctx.moveTo(p.p.x, p.p.y); } 別的 { ctx.lineTo(p.p.x, p.p.y); } } ctx. 中風(); } var ms = []; for(var i = 0; i < 10; i++) { ms.push(新M( Math.random() * 400 - 200, Math.random() * 400 - 200, Math.random() * 400 - 200)); } requestAnimationFrame(函數迴圈() { 請求動畫幀(循環); ctx.clearRect(0, 0, w, h); for(var i = 0; i < ms.length; i++) { var m = ms[i]; m.update(); prj(米); 更新(m,m.列表); } }); })(); </劇本>
這是一款基於HTML5 Canvas的酷炫3D線條延伸動畫效果,色彩變幻,非常漂亮!
免責聲明
本站所有資源皆由網友貢獻或各大下載網站轉載。請自行檢查軟體的完整性!本站所有資源僅供學習參考。請不要將它們用於商業目的。否則,一切後果都由您負責!如有侵權,請聯絡我們刪除。聯絡方式:admin@php.cn
相關文章
![CSS 轉換:「transition: all」還是「transition: x」比較快?](https://img.php.cn/upload/article/001/246/273/173323009728759.jpg)
03 Dec 2024
CSS3 過渡:「transition: all」與「transition: x」的效能影響關於 CSS3 過渡的效能效率,常見的...
![為什麼我的 CSS3 動畫在 Safari 中不起作用?](https://img.php.cn/upload/article/001/246/273/173417089227681.jpg)
14 Dec 2024
Safari 中 CSS3 動畫失效您遇到了 CSS3 動畫在 Safari 中無效的問題。儘管該動畫在支援 CSS3...
![See all articles](/static/imghw/down_right.png)
![](/static/imghw/taglogo.png)
Hot Tools
![CSS文字組合成心型動畫特效](https://img.php.cn/upload/jscode/000/000/001/5a41aee69fa64854.png)
CSS文字組合成心型動畫特效
CSS文字組合成心型動畫特效
![CSS3 SVG表白花動畫特效](https://img.php.cn/upload/jscode/000/000/001/58d8cebcc2691208.jpg)
CSS3 SVG表白花動畫特效
SS3 SVG表白花動畫特效是一款情人節動畫特效。
![CSS的商城網站常用左側分類下拉導覽選單代碼](https://img.php.cn/upload/jscode/000/000/001/5a3db819dcdbc612.png)
CSS的商城網站常用左側分類下拉導覽選單代碼
CSS的商城網站常用左側分類下拉導覽選單代碼
![jQuery+CSS3情人節愛心特效](https://img.php.cn/upload/jscode/000/000/001/58d8d3ea886c2698.jpg)
jQuery+CSS3情人節愛心特效
jQuery+CSS3情人節愛心特效是情人節懸掛擺動愛心動畫特效。
![css3湯匙撈起湯圓動畫特效](https://img.php.cn/upload/jscode/000/287/557/6209ad3adc2fc558.png)
css3湯匙撈起湯圓動畫特效
一碗可愛的湯圓表情,湯匙撈起一個湯圓動畫特效
![](/static/imghw/taglogo.png)
熱門文章
Tales Of Graces F 重製版:所有鎖定的寶箱密碼
18 Jan 2025
手游攻略
崩壞:星穹鐵道 - 所有金色替罪羊謎題解決方案
18 Jan 2025
手游攻略
王國來:拯救2-婚禮要買的衣服
05 Feb 2025
手游攻略
真三國無雙:起源 - 如何獲得每個結局
16 Jan 2025
手游攻略
王國來:拯救2-如何找到和領導伊格納修斯公羊
05 Feb 2025
手游攻略